Skip to content

[SES-PHASE-1-4] - PLU-744: add consumer for sqs events#1630

Merged
m0nggh merged 4 commits into
feat/ses/trunkfrom
feat/ses/add-sqs-poller-and-worker
Jun 8, 2026
Merged

[SES-PHASE-1-4] - PLU-744: add consumer for sqs events#1630
m0nggh merged 4 commits into
feat/ses/trunkfrom
feat/ses/add-sqs-poller-and-worker

Conversation

@m0nggh

@m0nggh m0nggh commented May 19, 2026

Copy link
Copy Markdown
Contributor

TL;DR

Adds an SQS-backed consumer for processing SES email events (bounces, complaints, etc.) directly in the worker process using sqs-consumer.

What changed?

  • Added @aws-sdk/client-sqs and sqs-consumer as dependencies.
  • Introduced ses-consumer.ts, which creates an SQS long-polling consumer via Consumer.create with a batch size of 10 and a 20-second wait time. Messages are parsed via the existing parseSqsMessage helper and dispatched to processSesEvent.
  • Returning the message from handleMessage signals sqs-consumer to delete (ack) it; throwing propagates the error so SQS redelivers the message according to the queue's MaxReceiveCount.
  • Malformed/unparseable messages are treated as poison messages: they are logged with a body preview and immediately acked to prevent indefinite redelivery until a DLQ is in place.
  • Structured error logging is wired to the consumer's error and processing_error events.
  • Graceful shutdown is handled via a SIGTERM listener that calls consumer.stop() and awaits the stopped event before logging completion. pollingCompleteWaitTimeMs caps the internal wait, so no external timeout race is needed.
  • startSesConsumer is idempotent — repeated calls after the consumer is already running are no-ops.
  • Added sqsQueueUrl to the app config, sourced from the SQS_QUEUE_URL environment variable. If unset, the consumer does not start and logs an informational message.
  • Registered startSesConsumer in the main worker entrypoint (worker.ts).

How to test?

  1. Set SQS_QUEUE_URL to a valid AWS SQS queue URL in your environment.
  2. Ensure AWS credentials with SQS read and delete permissions are available (done)
  3. Start the worker process and confirm the log line SES consumer started appears.
  4. Send a valid email and it should go to the SQS queue and verify processSesEvent is invoked and the message is deleted from the queue.
  5. Send to a bounced email address: bounce@simulator.amazonses.com and it should go to the SQS queue and verify processSesEvent is invoked and the message is deleted from the queue.
    1. The entry should be inserted into the DB table
  6. Omit SQS_QUEUE_URL and confirm the consumer does not start and logs SQS_QUEUE_URL not set.

Why make this change?

SES delivers email event notifications (bounces, complaints, deliveries) via SNS→SQS. This consumer reliably ingests those events directly in the worker process with structured error handling and graceful shutdown, rather than requiring an additional BullMQ queue layer for this use case.

@m0nggh m0nggh force-pushed the feat/ses/add-parser-and-worker-processor branch from 66e7e1a to 7fa6e51 Compare May 19, 2026 09:22
@m0nggh m0nggh force-pushed the feat/ses/add-sqs-poller-and-worker branch from 75e68cc to 382a321 Compare May 19, 2026 09:22
@m0nggh m0nggh force-pushed the feat/ses/add-parser-and-worker-processor branch from 7fa6e51 to 901af9b Compare May 19, 2026 09:50
@m0nggh m0nggh force-pushed the feat/ses/add-sqs-poller-and-worker branch from 382a321 to 899d39c Compare May 19, 2026 09:50
@m0nggh m0nggh changed the title add queue for ses events [SES-PHASE-1-4] - PLU-744: add queue for ses events May 19, 2026
@linear

linear Bot commented May 19, 2026

Copy link
Copy Markdown

PLU-744

@ogp-weeloong ogp-weeloong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no need extra queue here

@m0nggh m0nggh force-pushed the feat/ses/add-sqs-poller-and-worker branch from 899d39c to 5e6000c Compare May 22, 2026 11:16
@m0nggh m0nggh changed the title [SES-PHASE-1-4] - PLU-744: add queue for ses events [SES-PHASE-1-4] - PLU-744: add consumer for sqs events May 22, 2026
Comment thread packages/backend/src/helpers/ses-consumer.ts
Comment thread packages/backend/src/helpers/ses-consumer.ts
Comment thread packages/backend/src/helpers/ses-consumer.ts
Comment thread packages/backend/src/worker.ts

@ogp-weeloong ogp-weeloong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

generally OK.

@m0nggh m0nggh force-pushed the feat/ses/add-sqs-poller-and-worker branch from 5e6000c to bea7df4 Compare June 8, 2026 09:03
@m0nggh m0nggh force-pushed the feat/ses/add-parser-and-worker-processor branch from b0fd3f3 to 3fddfc4 Compare June 8, 2026 09:03
@m0nggh m0nggh force-pushed the feat/ses/add-sqs-poller-and-worker branch from bea7df4 to f68ee3e Compare June 8, 2026 11:01
@m0nggh m0nggh force-pushed the feat/ses/add-parser-and-worker-processor branch from 3fddfc4 to 59cbb20 Compare June 8, 2026 11:01
@m0nggh m0nggh force-pushed the feat/ses/add-sqs-poller-and-worker branch from f68ee3e to d0a0ee3 Compare June 8, 2026 12:02
@m0nggh m0nggh force-pushed the feat/ses/add-parser-and-worker-processor branch 2 times, most recently from 8c50986 to 95b7b1c Compare June 8, 2026 12:04
@m0nggh m0nggh force-pushed the feat/ses/add-sqs-poller-and-worker branch from d0a0ee3 to 3a2ce7a Compare June 8, 2026 12:04
@m0nggh m0nggh requested a review from Copilot June 8, 2026 12:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an SQS-backed SES event consumer to the backend worker process, enabling the worker to long-poll an SES SNS→SQS queue and dispatch parsed SES events to the existing processSesEvent handler with structured logging and graceful shutdown behavior.

Changes:

  • Start an SES SQS consumer from the worker entrypoint when SQS_QUEUE_URL is configured.
  • Add ses-consumer.ts implementing the sqs-consumer wiring, poison-message handling, and SIGTERM shutdown.
  • Add config + unit tests for the new consumer and introduce required SQS dependencies.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/backend/src/worker.ts Starts the SES SQS consumer when the worker boots.
packages/backend/src/helpers/ses-consumer.ts Implements SQS long-polling consumer, parsing, dispatch, logging, and SIGTERM shutdown.
packages/backend/src/helpers/tests/ses-consumer.test.ts Unit tests for consumer start/stop/idempotency, poison-message handling, and SIGTERM flow.
packages/backend/src/config/app.ts Adds ses.sqsQueueUrl sourced from SQS_QUEUE_URL.
packages/backend/package.json Adds @aws-sdk/client-sqs and sqs-consumer dependencies.
package-lock.json Locks new dependency tree for SQS consumer support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/backend/src/helpers/ses-consumer.ts
Comment thread packages/backend/src/helpers/ses-consumer.ts Outdated
@m0nggh m0nggh force-pushed the feat/ses/add-parser-and-worker-processor branch from 95b7b1c to cdaa0e1 Compare June 8, 2026 15:02
@m0nggh m0nggh force-pushed the feat/ses/add-sqs-poller-and-worker branch from 3a2ce7a to d760c96 Compare June 8, 2026 15:02
@m0nggh m0nggh force-pushed the feat/ses/add-parser-and-worker-processor branch from cdaa0e1 to 79a7684 Compare June 8, 2026 15:03
@m0nggh m0nggh force-pushed the feat/ses/add-sqs-poller-and-worker branch 2 times, most recently from 1bbf41b to 32c4d9d Compare June 8, 2026 16:00
Base automatically changed from feat/ses/add-parser-and-worker-processor to feat/ses/trunk June 8, 2026 16:01
@m0nggh m0nggh force-pushed the feat/ses/add-sqs-poller-and-worker branch from 32c4d9d to fae6822 Compare June 8, 2026 16:02
@m0nggh m0nggh merged commit cfcde12 into feat/ses/trunk Jun 8, 2026
3 checks passed
@m0nggh m0nggh deleted the feat/ses/add-sqs-poller-and-worker branch June 8, 2026 16:49
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.

3 participants