Skip to content

fix(backfill): anchor nightly backfill to a fixed wall clock via cron#196

Merged
entrius merged 3 commits into
testfrom
fix/backfill-cron-wallclock
Jun 24, 2026
Merged

fix(backfill): anchor nightly backfill to a fixed wall clock via cron#196
entrius merged 3 commits into
testfrom
fix/backfill-cron-wallclock

Conversation

@anderdc

@anderdc anderdc commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Problem

The nightly backfill scheduled itself with setInterval(24h) registered in onModuleInit, so its fire time was boot + N×24h — anchored to whatever time the process last restarted, not a real clock. Every redeploy silently shifted the window. After PR #195's deploy it landed at ~03:35 UTC instead of the historical 00:10 UTC, purely because the container happened to reboot at 03:35. That makes the schedule unpredictable and the rate-limit verification window a moving target (the working notes had to keep re-deriving it from docker inspect ... StartedAt).

Fix

Switch to @nestjs/schedule's @Cron, which evaluates against the wall clock and is stable across redeploys. The infra is already in place — ScheduleModule.forRoot() is registered in app.module.ts and MaintainerPopulateService already uses @Cron.

  • Hardcoded '10 0 * * *' in America/Chicago12:10am local, year-round (the timeZone option handles the CST/CDT shift, so it doesn't wander an hour twice a year).
  • The :10 offset preserves the prior 00:10 off-the-top-of-the-hour stagger.

Behavior preserved

  • No run-at-startup (a deploy already implies fresh data; this is the heavy job).
  • NIGHTLY_BACKFILL_ENABLED=false still disables it (guarded in both onModuleInit logging and the job body).
  • The static per-repo jobId: backfill-<repo>-nightly still dedupes a tick that lands while the prior night's run is still draining — so dropping the boot-anchored timer loses nothing.
  • Removed the now-unused NIGHTLY_BACKFILL_INTERVAL_MS knob from .env.example. The cron/timezone are plain constants (they won't realistically change), not env vars.

Test

  • tsc --noEmit, eslint, prettier --check: clean.
  • npm test (das): 21/21 pass.

Deploy note

After this deploys, the nightly fires at 00:10 America/Chicago going forward, regardless of reboot time — no more re-deriving the window from container boot.

anderdc added 3 commits June 24, 2026 11:09
The nightly backfill used setInterval(24h) registered in onModuleInit, so its
fire time was boot + N*24h — anchored to whatever time the process last
restarted. Every redeploy silently moved the window (most recently to ~03:35
UTC), making the schedule unpredictable and the verification window a moving
target.

Switch to @nestjs/schedule's @Cron (ScheduleModule is already wired up and used
by MaintainerPopulateService). Default '10 0 * * *' in America/Chicago = 12:10am
local, stable across redeploys, with timeZone handling the CST/CDT shift so it
stays at local midnight year-round. Overridable via NIGHTLY_BACKFILL_CRON /
NIGHTLY_BACKFILL_TZ; the :10 offset preserves the prior 00:10 stagger.

Behavior preserved: still no run-at-startup, NIGHTLY_BACKFILL_ENABLED still
disables it, and the static per-repo jobId still dedupes overlapping ticks.
Replaces the removed NIGHTLY_BACKFILL_INTERVAL_MS knob in .env.example.
The cron expression and timezone won't realistically change, so drop the
NIGHTLY_BACKFILL_CRON / NIGHTLY_BACKFILL_TZ env indirection and make them plain
constants. Condense the surrounding comments.
PR #195 dropped DEFAULT_BACKFILL_DAYS 40->10 but .env.example kept the stale 40.
@entrius entrius merged commit 4ead3f5 into test Jun 24, 2026
3 checks passed
@entrius entrius deleted the fix/backfill-cron-wallclock branch June 24, 2026 17:29
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