fix(email-scheduler): double-start guard, deterministic jobId, repo organisation#575
Merged
zbigniewsobiecki merged 1 commit intodevfrom Feb 27, 2026
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three robustness fixes identified during code review of the email-joke scheduler:
startEmailScheduler()now mirrorsstartWorkerProcessor(): a second call logs[EmailScheduler] Scheduler already startedand returns early, preventing two concurrentsetIntervalloops.submitDashboardJobgains an optionaljobId?parameter (all existing callers unchanged). The scheduler passes a deterministicemail-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).getAllProjectIdsWithEmailIntegrationmoved into the existing// Project Integrationssection ofsettingsRepository.ts(afterdeleteProjectIntegration), removing the isolated// Email Integration Queriessection it had been placed in. Also fixes a trailing-newline lint error.Files changed
src/queue/client.tsjobId?param onsubmitDashboardJobsrc/router/email-scheduler.tssrc/db/repositories/settingsRepository.tssrc/router/config.tsemailScheduleIntervalMsfield (pre-existing, now tracked)src/router/index.tsTest plan
tests/unit/router/email-scheduler.test.tscovering start guard, stop idempotency, restart, interval ticks, deterministic jobId, error resiliencetests/unit/db/repositories/settingsRepository.test.tsforgetAllProjectIdsWithEmailIntegrationtests/unit/router/config.test.tsforemailScheduleIntervalMsdefault🤖 Generated with Claude Code