Fix double ScheduleModule.forRoot() — all cron jobs fired twice (v0.21.7) #50

Merged
kamilkrzywda merged 1 commits from fix/schedule-double-registration into main 2026-09-27 08:52:35 +02:00
Owner

Owner report: "sometimes you are sending 2 weather reports at time". Data showed it was NOT sometimes — every hourly broadcast for the last 12+ h was duplicated (identical text, 0–3 s apart), single container / single node process.

Root cause (verified in installed @nestjs/schedule@12): ScheduleModule.forRoot() was called TWICE — weather.module.ts:7 and battery.module.ts:7. Nest gives each dynamic-module object its own token → two ScheduleExplorer/SchedulerOrchestrator instances, each scanning ALL app providers and registering every @Cron/@Interval method → all scheduled jobs fire twice. Battery's per-minute check was doubled too but masked by its 6 h cooldown map; weather has no such guard so it showed up as duplicate broadcasts.

  • Removed the second ScheduleModule.forRoot() from battery.module.ts (keeps the one in weather.module.ts)
  • New regression test: walks all src/**/*.module.ts and asserts ScheduleModule.forRoot( appears exactly once (negative control verified: 2 on main, 1 after fix)

Tests 174 → 175. Build clean, oxlint clean. Lockfile untouched.

Owner report: "sometimes you are sending 2 weather reports at time". Data showed it was NOT sometimes — every hourly broadcast for the last 12+ h was duplicated (identical text, 0–3 s apart), single container / single node process. Root cause (verified in installed @nestjs/schedule@12): `ScheduleModule.forRoot()` was called TWICE — weather.module.ts:7 and battery.module.ts:7. Nest gives each dynamic-module object its own token → two ScheduleExplorer/SchedulerOrchestrator instances, each scanning ALL app providers and registering every @Cron/@Interval method → all scheduled jobs fire twice. Battery's per-minute check was doubled too but masked by its 6 h cooldown map; weather has no such guard so it showed up as duplicate broadcasts. - Removed the second `ScheduleModule.forRoot()` from battery.module.ts (keeps the one in weather.module.ts) - New regression test: walks all src/**/*.module.ts and asserts `ScheduleModule.forRoot(` appears exactly once (negative control verified: 2 on main, 1 after fix) Tests 174 → 175. Build clean, oxlint clean. Lockfile untouched.
kamilkrzywda added 1 commit 2026-09-27 08:52:29 +02:00
kamilkrzywda merged commit 0b20df242c into main 2026-09-27 08:52:35 +02:00
kamilkrzywda deleted branch fix/schedule-double-registration 2026-09-27 08:52:35 +02:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: OpenCode/MeshBot#50