Skip to content

fix(email-scheduler): double-start guard, deterministic jobId, repo organisation#575

Merged
zbigniewsobiecki merged 1 commit intodevfrom
fix/email-scheduler-robustness
Feb 27, 2026
Merged

fix(email-scheduler): double-start guard, deterministic jobId, repo organisation#575
zbigniewsobiecki merged 1 commit intodevfrom
fix/email-scheduler-robustness

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

Three robustness fixes identified during code review of the email-joke scheduler:

  • Double-start guardstartEmailScheduler() now mirrors startWorkerProcessor(): a second call logs [EmailScheduler] Scheduler already started and returns early, preventing two concurrent setInterval loops.
  • Deduplicating jobIdsubmitDashboardJob gains an optional jobId? parameter (all existing callers unchanged). The scheduler passes a deterministic email-joke-{projectId}-{windowId} ID so BullMQ silently rejects a duplicate job submitted within the same interval window — prevents double-sends when a prior run is still in flight (worker timeout up to 30 min, scheduler interval 5 min).
  • Repository organisationgetAllProjectIdsWithEmailIntegration moved into the existing // Project Integrations section of settingsRepository.ts (after deleteProjectIntegration), removing the isolated // Email Integration Queries section it had been placed in. Also fixes a trailing-newline lint error.

Files changed

File Change
src/queue/client.ts Optional jobId? param on submitDashboardJob
src/router/email-scheduler.ts Double-start guard + deterministic window jobId
src/db/repositories/settingsRepository.ts Move function into correct section; fix trailing newline
src/router/config.ts emailScheduleIntervalMs field (pre-existing, now tracked)
src/router/index.ts Scheduler start/stop wiring (pre-existing, now tracked)

Test plan

  • 13 new unit tests in tests/unit/router/email-scheduler.test.ts covering start guard, stop idempotency, restart, interval ticks, deterministic jobId, error resilience
  • 2 new cases in tests/unit/db/repositories/settingsRepository.test.ts for getAllProjectIdsWithEmailIntegration
  • 1 new case in tests/unit/router/config.test.ts for emailScheduleIntervalMs default
  • Full suite: 3457 tests pass locally

🤖 Generated with Claude Code

…rganisation

Three robustness fixes for the email-joke scheduler:

1. **Double-start guard** — `startEmailScheduler()` now mirrors
   `startWorkerProcessor()`: a second call logs a warning and returns
   early instead of creating a second concurrent `setInterval` loop.

2. **Deduplicating jobId** — `submitDashboardJob` accepts an optional
   `jobId` parameter (existing callers unchanged).  The scheduler passes
   a deterministic `email-joke-{projectId}-{windowId}` ID so BullMQ
   silently rejects a duplicate job that arrives within the same interval
   window (prevents double-sends when a prior run is still in flight).

3. **Repository organisation** — `getAllProjectIdsWithEmailIntegration`
   moved into the existing `// Project Integrations` section of
   `settingsRepository.ts` (after `deleteProjectIntegration`, before
   `// Integration Credentials`), removing the stray
   `// Email Integration Queries` section it had been placed in.

Also fixes a trailing-newline lint error in `settingsRepository.ts`.

Tests: 13 new tests in `email-scheduler.test.ts`; 2 new cases in
`settingsRepository.test.ts`; 1 new case in `config.test.ts`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zbigniewsobiecki zbigniewsobiecki merged commit 8c6a447 into dev Feb 27, 2026
6 checks passed
@zbigniewsobiecki zbigniewsobiecki deleted the fix/email-scheduler-robustness branch February 27, 2026 18:08
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.

1 participant