Skip to content

feat: async email sending via BullMQ queue (closes background-jobs task)#14

Merged
sumdahl merged 1 commit into
mainfrom
feat/async-email-queue
May 14, 2026
Merged

feat: async email sending via BullMQ queue (closes background-jobs task)#14
sumdahl merged 1 commit into
mainfrom
feat/async-email-queue

Conversation

@sumdahl

@sumdahl sumdahl commented May 14, 2026

Copy link
Copy Markdown
Owner

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).

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).
Copilot AI review requested due to automatic review settings May 14, 2026 04:26
@sumdahl
sumdahl merged commit 72c8e6b into main May 14, 2026
2 checks passed
@sumdahl
sumdahl deleted the feat/async-email-queue branch May 14, 2026 04:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 QueuedEmailService as 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(),
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.

2 participants