[TTAHUB-5390] Make registering new email notifications/email digests easier#3664
Open
thewatermethod wants to merge 13 commits into
Open
[TTAHUB-5390] Make registering new email notifications/email digests easier#3664thewatermethod wants to merge 13 commits into
thewatermethod wants to merge 13 commits into
Conversation
Documents the full lifecycle of an email (trigger → Bull queue → handler → email-templates → SMTP), all notification categories (instant, digest, training report, special), key helpers (createEmailSender, sendIfEnabled, enqueueNotification, DIGEST_CONFIG), environment variables, and step-by-step recipes for registering new instant, digest, and training-report notifications. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
|
|
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the mailer/cron email-notification plumbing to reduce duplication and make it easier to register new notification/digest types while preserving existing email behavior.
Changes:
- Introduces shared mailer helpers (
createEmailSender,sendIfEnabled,enqueueNotification) and refactors notification handlers to use them. - Adds a declarative digest registry (
DIGEST_CONFIG) and a shared digest runner (digestForSetting), then updates cron to iterate the registry. - Adds/updates tests for the new digest registry/runner and documents the email notification architecture; updates local docker compose to point SMTP to mailpit.
Impact assessment: Benefits medium (less duplication, clearer extension points); risks medium (touches core notification sending + cron scheduling/logging paths).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/mailer/index.js | Refactors email send/enqueue logic, adds DIGEST_CONFIG + digestForSetting, consolidates queue processors. |
| src/lib/mailer/index.test.js | Adds tests covering the new helpers/registry behavior. |
| src/lib/cron.js | Consolidates daily/weekly/monthly digest jobs into a single configurable digest runner over DIGEST_CONFIG. |
| src/lib/cron.test.js | Updates cron tests to validate iteration via DIGEST_CONFIG/digestForSetting. |
| docs/email_notifications.md | New developer documentation describing notification lifecycle and how to register new email types. |
| docker/compose/docker-compose.yml | Sets SMTP_HOST to mailpit for local docker environment. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Replace numeric-index lookups (DIGEST_CONFIG[0], etc.) with semantic key lookups (DIGEST_CONFIG[EMAIL_ACTIONS.X]). This eliminates positional coupling so that adding, removing, or reordering digest types no longer risks silent breakage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ACTIONS from DIGEST_CONFIG - Remove hard-coded SMTP_HOST=mailpit from always-on backend service in docker-compose.yml; mailpit only exists in the fullstack profile so core-stack runs were pointing at a non-existent SMTP host - Document that SMTP_HOST=mailpit must be set in .env when running yarn docker:start:full for local email testing (email_notifications.md, dev-setup.md) - Fix command typo: 'docker start:full' → 'yarn docker:start:full' in docs/email_notifications.md - Derive DIGEST_EMAIL_ACTIONS from Object.keys(DIGEST_CONFIG) so any new digest added to DIGEST_CONFIG automatically gets a Bull processor registered, preventing schedule-without-processor bugs - Add test asserting processNotificationQueue registers a processor for every DIGEST_CONFIG entry plus RECIPIENT_REPORT_APPROVED_DIGEST Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Description of change
Simplify adding a new email notification by "dry"-ing up the code. Everything should work exactly the same before and after this change.
How to test
Locally:
FORCE_CRON=true(to test digests) as well asSEND_NOTIFICATIONS=trueandSEND_NON_PRODUCTION_NOTIFICATIONS=truedocker start:fullsrc/lib/cron.jsIssue(s)
Checklists
Every PR
Before merge to main
Production Deploy
ready_for_reviewtransition triggers the Slack/Jira automation)elainaparrishis the authorized approver under normal circumstances)After merge/deploy