Replace ad-hoc cron Scheduler with chained-timeout helper#595
Conversation
The EventEmitter-based Scheduler class wrapped setInterval to no real benefit and each of the three cache crawlers duplicated ~60 lines of boilerplate around it. This collapses the lot into two small helpers (scheduleRepeating, warmAll) and a shared interval constant, taking the cron-jobs/ directory from ~190 lines to ~110. Behavior changes: - Chained setTimeout instead of setInterval, so a slow run can't overlap with the next one if a warmup ever takes longer than the interval. - Per-action failures inside a warmup are collected (Promise.allSettled) rather than aborting the rest, then re-thrown to surface to the scheduler-level log. - SIGTERM and SIGINT now call .stop() on every active scheduler so the pending timer is cleared on shutdown. - One named constant (CACHE_WARM_INTERVAL_MS) replaces the magic `60 * 59 * 1000` repeated in each crawler, with a comment explaining the relationship to the 60-minute service cache TTL. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThe PR replaces a monolithic EventEmitter-based ChangesScheduler Replacement and Graceful Shutdown
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
src/backend/cron-jobs/:scheduleRepeating(chainedsetTimeout, can't overlap, returns a.stop()handle) andwarmAll(collects per-action failures viaPromise.allSettled, logs each, then throws so the scheduler-level log records the failure).CACHE_WARM_INTERVAL_MSconstant inconstants.jsreplaces the magic60 * 59 * 1000that was duplicated in each crawler. Comment explains the relationship to the 60-minute service cache TTL.leaderboard,wordpress,clan) shrink to ~15 lines each — just a list of named warmup actions.AppKernel.startCronJobsnow registersSIGTERM/SIGINThandlers that call.stop()on every scheduler, so the pending timer is cleared on shutdown (no leaked timers under nodemon or Docker stop).services/Scheduler.js(22 lines wrappingsetIntervalfor no real benefit).Net diff: +116 / -196 across 8 files;
cron-jobs/directory goes from ~190 LOC to ~110.Why
The previous
Schedulerclass added indirection without value, and each crawler reimplemented the same boilerplate (per-call success/error handlers, magic interval constant, top-level catch). Three concrete bugs/risks the cleanup also fixes:setIntervalcould schedule a second warmup before the previous one finished — now impossible because the next timer is only set infinallyafter the run completes.stopwould leak callbacks until the process exited.This deliberately does not introduce
node-cronor a job queue (BullMQ etc.) — neither would solve a real problem here, and both would add deps.Test plan
yarn lintcleanyarn test— 71/71 (tests don't exercisestartCronJobs, but they do boot AppKernel and would catch import-level breakage)[scheduler] leaderboard-cache ok in Xms(orfailed) lines appear at startup and roughly every 59 minutesdocker stopthe running container, confirm the process exits cleanly (no lingering timer warnings)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor