Repository navigation
fix(maintenance): start the loop on the next interval step - #14885
Conversation
Moves the first-run computation into Maintenance::next() unchanged and adds cases for sub-daily intervals. The hourly and 8-hourly cases fail: a restart waits for the next daily start time instead of the next interval step.
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
The first run waited for the next start time, so with an interval under a day every restart could hold the loop back by up to a day. It now runs at the next point of start time + k x interval, at most one interval away. Daily intervals keep the same schedule.
|
Review complete. 🟡 2 medium 💬 Inline comments (1)
📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Non-positive // src/Appwrite/Platform/Tasks/Maintenance.php
45 $interval = (int) System::getEnv('_APP_MAINTENANCE_INTERVAL', '86400'); // 1 day
46 $cacheRetention = (int) System::getEnv('_APP_MAINTENANCE_RETENTION_CACHE', '2592000'); // 30 days
47 $schedulesDeletionRetention = (int) System::getEnv('_APP_MAINTENANCE_RETENTION_SCHEDULES', '86400'); // 1 Day
48 $jobInitTime = System::getEnv('_APP_MAINTENANCE_START_TIME', '00:00'); // (hour:minutes)
49
50 $now = new \DateTime();
51 $now->setTimezone(new \DateTimeZone(date_default_timezone_get()));
52 $next = self::next($now, $jobInitTime, $interval);
The change replaces the maintenance task's fixed daily cadence with an interval-driven schedule anchored to a configurable start time, and adds unit tests for the new
Reviewed commit: a69535d |
🟢 Tier S · Ready to mergeMaintenance now calculates the first loop run as the next strictly future point on the configured start-time and interval grid, avoiding long restart delays for subdaily intervals. The calculation lives in Latest changes: Adds regression cases for hourly and daily schedules when the current time is several hours before the configured start time.
📂 Walkthrough · 3
Reviewed the commits since |
Unit tests cover src libraries, not CLI tasks, so the first-run computation lives in Appwrite\Maintenance\Grid and the task only calls it.
There was a problem hiding this comment.
This PR reworks the maintenance scheduler's next-run calculation to anchor runs to _APP_MAINTENANCE_START_TIME and lets _APP_MAINTENANCE_INTERVAL configure the cadence, plus a unit test.
Key findings
- 🟡
next()returns a past time whennowprecedes the anchor by more than one interval — Maintenance.php:117 - 🟡 Non-positive
_APP_MAINTENANCE_INTERVALcrashes or busy-loops maintenance — Maintenance.php:45
Grid steps before the start time land on earlier points of the same grid, so 10:00 with an hourly 12:00 grid runs at 11:00, not in the past.
…-grid fix(maintenance): start the loop on the next interval step (cherry picked from commit de0677d)
Maintenance's first run waited for the next
_APP_MAINTENANCE_START_TIME, so with_APP_MAINTENANCE_INTERVALunder a day every restart could delay the loop by up to ~24h. The first run now lands on the next step of the gridstart + k × interval.Start time
12:00:Daily runs are unchanged. The computation lives in
Appwrite\Maintenance\Grid, covered bytests/unit/Maintenance/GridTest.php.Related: appwrite-labs/cloud#6628