Commit 9f10cf2
committed
fix(selfhost): phase-align the cron scheduler to wall-clock boundaries
Cloudflare's own */2 * * * * cron trigger fires exactly on wall-clock
2-minute boundaries (:00, :02, :04, ...), which every minute-gated job
in enqueueScheduledJobs (minute % 10 === 0, minute === 0, minute % 30
=== 0 -- all even) depends on to ever run. The self-host entrypoint's
plain setInterval instead ticked every CRON_INTERVAL_MS from whatever
moment the container booted, with no relation to wall-clock
boundaries -- and since the interval evenly divides an hour, that
locks every tick to a FIXED minute parity for the container's entire
lifetime. A container booting in an odd minute then ticks ONLY on odd
minutes forever, so refresh-registry, ops-alerts, sweep-watchdog,
backfill-registered-repos, and both reconciliation sweeps silently
NEVER fire.
Confirmed live on edge-nl-01: the app container booted at :49 (odd)
and ran 3+ hours of on-schedule ~2-minute ticks with zero occurrences
of any minute-gated job, while the unconditional every-tick sweep ran
normally the whole time.
Phase-align the first tick to the next true wall-clock boundary
(computed from epoch, itself minute-aligned) with a one-shot
setTimeout, then hand off to setInterval from that aligned moment.1 parent b63fa69 commit 9f10cf2
3 files changed
Lines changed: 65 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
1090 | 1091 | | |
1091 | 1092 | | |
1092 | 1093 | | |
1093 | | - | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
1094 | 1108 | | |
1095 | 1109 | | |
1096 | | - | |
| 1110 | + | |
1097 | 1111 | | |
1098 | 1112 | | |
1099 | 1113 | | |
| |||
1110 | 1124 | | |
1111 | 1125 | | |
1112 | 1126 | | |
1113 | | - | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
1114 | 1132 | | |
1115 | 1133 | | |
1116 | 1134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
0 commit comments