feat: async email sending via BullMQ queue (closes background-jobs task)#14
Merged
Conversation
Replace inline await on Resend API calls with BullMQ job queue. Use-cases unchanged — QueuedEmailService decorates IEmailService, enqueues jobs instead of blocking on Resend. Worker processes emails asynchronously with exponential backoff retries (3 attempts).
There was a problem hiding this comment.
Pull request overview
Adds BullMQ-backed asynchronous email processing so auth flows enqueue verification/password-reset email work instead of waiting on Resend inline.
Changes:
- Introduces an email queue, queue payload types, and a BullMQ worker that sends emails via
ResendEmailService. - Registers
QueuedEmailServiceas the DI email service and starts/closes the worker from the app entrypoint. - Adds BullMQ dependency/lock updates and marks the background-jobs task as done.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/server/infrastructure/queue/index.ts |
Defines Redis queue connection, email queue defaults, and email job payload types. |
src/server/infrastructure/queue/email.worker.ts |
Adds BullMQ worker for verification and password-reset email jobs. |
src/server/infrastructure/email/queued-email.service.ts |
Implements IEmailService by enqueueing email jobs. |
src/server/infrastructure/di/container.ts |
Switches DI registration from direct Resend email service to queued email service. |
src/index.ts |
Starts the worker and adds graceful shutdown for worker/queue/Redis resources. |
package.json |
Adds BullMQ dependency. |
bun.lock |
Locks BullMQ and transitive dependencies. |
docs/tasks/prod-addon-background-jobs.md |
Marks the background-jobs task as completed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+19
to
+21
| export type EmailJobData = | ||
| | { type: "send-verification"; to: string; name: string; token: string } | ||
| | { type: "send-password-reset"; to: string; name: string; token: string }; |
| import { Redis } from "ioredis"; | ||
| import { env } from "../../config/env"; | ||
|
|
||
| export const queueConnection = new Redis(env.REDIS_URL, { |
| roleRepository: asClass(PostgresRoleRepository).singleton(), | ||
|
|
||
| emailService: asClass(ResendEmailService).singleton(), | ||
| emailService: asClass(QueuedEmailService).singleton(), |
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.
Replace inline await on Resend API calls with BullMQ job queue. Use-cases unchanged — QueuedEmailService decorates IEmailService, enqueues jobs instead of blocking on Resend. Worker processes emails asynchronously with exponential backoff retries (3 attempts).