Skip to content

Make the schedule spread window overridable per schedule - #13122

Merged
levivannoort merged 1 commit into
mainfrom
feat/schedule-spread-window-seam
Aug 6, 2026
Merged

levivannoort merged 1 commit into
mainfrom
feat/schedule-spread-window-seam

Conversation

@levivannoort

Copy link
Copy Markdown
Member

What does this PR do?

Follow-up to #13121. Extracts the schedule-spread window into a protected seam:

protected function spreadWindow(array $schedule, Database $dbForPlatform): int

The default implementation is behavior-identical to #13121 — _APP_FUNCTIONS_SCHEDULE_SPREAD (default 0 = off) applied to every schedule. Subclassing platforms can override the method to scope or vary the window per schedule — e.g. spread only certain projects or plan tiers — without having to copy the ~90-line enqueue loop, which was the only extension point before this.

The call site consults the seam per current-tick schedule; spreadOffset() and selection semantics are untouched.

Test plan

  • New unit test covers the default seam via a probe subclass (no reflection): env set → window, env unset → 0, with the env restored afterwards.
  • Existing spreadOffset tests unchanged and passing.
  • Pint, Rector, and PHPStan (level 4) pass.

🤖 Generated with Claude Code

Extracts the spread window into a protected spreadWindow() seam. The
default behavior is unchanged (_APP_FUNCTIONS_SCHEDULE_SPREAD applied
to every schedule); platform subclasses can override it to scope or
vary the window per schedule (e.g. by project or plan) without copying
the enqueue loop.

Co-Authored-By: Claude Fable 5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR introduces a protected seam for selecting the function-schedule spread window while preserving the existing environment-based default.

  • Adds spreadWindow() so subclasses can vary the spread window per schedule.
  • Updates the enqueue loop to consult the seam for each schedule.
  • Adds unit coverage for configured and unset environment values.

Confidence Score: 5/5

The PR appears safe to merge with no concrete blocking or non-blocking defects identified.

The default implementation preserves the existing environment-derived spread window, and the offset and delay calculations remain unchanged aside from allowing deliberate per-schedule overrides.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Tasks/ScheduleFunctions.php Extracts the environment-derived spread window into an overridable protected method without changing default scheduling behavior.
tests/unit/Platform/Tasks/ScheduleFunctionsTest.php Adds focused coverage confirming that the new seam returns the configured value and defaults to zero while restoring process environment state.

Reviews (1): Last reviewed commit: "Make the schedule spread window overrida..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/schedule-spread-window-seam (after).

Metric Before After Change
🚀 Requests/sec 163.47 163.53 ⚪ 0%
⏱️ Latency P50 88.52 ms 88.17 ms ⚪ -0.4%
⏱️ Latency P95 303.01 ms 308.81 ms ⚪ +1.9%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 88.17 308.81 10,317 163.53 +5.8
Account 162.71 396.71 543 9.23 -42.64
TablesDB 83.88 285.74 5,611 90.48 +12.87
Storage 78.27 274.96 2,715 45.79 -4.28
Functions 135.95 364.9 1,448 25.03 -30.63

Top API waits (after)

API request Max wait (ms)
functions.runtimes.list 895.7
tablesdb.rows.delete 837.14
tablesdb.rows.create 810.31
functions.create 765.24
functions.specifications.list 744.21

@levivannoort
levivannoort merged commit 42af673 into main Aug 6, 2026
83 of 84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants