Skip to content

feat(jobs): enqueue pg-boss jobs in application transactions - #209

Merged
theosiemensrhodes merged 14 commits into
mainfrom
feat/transactional-email-outbox
Nov 23, 2026
Merged

theosiemensrhodes merged 14 commits into
mainfrom
feat/transactional-email-outbox

Conversation

@theosiemensrhodes

@theosiemensrhodes theosiemensrhodes commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Account-status changes and notification fan-out can commit before asynchronous enqueueing fails. Extend JobService.run(..., { transaction }) to insert native pg-boss jobs through the same Drizzle/postgres-js transaction, so application state and job intent commit or roll back together.

Use pg-boss's Db adapter interface, native job IDs, cancellation, retries and worker lifecycle. The adapter binds parameterized SQL through Drizzle's public API and normalizes postgres-js results. Account approval/reactivation/deactivation and notification email fan-out use transactional enqueueing.

Keyed transactional producers serialize until commit. Replacement cancels pending/active native jobs and inserts a fresh job ID atomically. Cancellation rechecks native state to handle a concurrent retry deleting/reinserting a job row, and fails the caller transaction if cancellation cannot settle. Handlers can check cooperative cancellation before external side effects.

TypeScript unions express valid recurring, one-off and replacement options. Keep one defensive guard at the cancellation boundary; pg-boss validates native option values. Enqueue options are assembled directly without a nested builder or an any cast.

Scope: startup/readiness/recovery is owned by #214; shift and coverage event propagation is owned by #220. This PR does not change the DI bootstrap or startup/shutdown lifecycle, add startup tests, or modify unrelated coverage fixtures. #210 consumes the transactional assignment API. No custom outbox table, application migration, delivery registry, polling worker or dependency is added.

Validation on the combined #209/#210 stack: TypeScript and production build pass; formatting checks pass for changed job-service/test code. All 10 test files outside coverage-service.test.ts pass. Full run: 117 tests passed and 21 failed; all failures are the existing coverage tests rejecting July 2026 fixture shifts as past. The coverage fixture file is identical to main. Integration coverage includes transaction visibility, rollback/enqueue failure, idempotency, native retry/cancellation races, concurrent producers/account transitions and atomic fan-out.

SMTP acceptance followed by a crash before pg-boss records completion remains the standard at-least-once delivery limitation.

@theosiemensrhodes theosiemensrhodes changed the title feat(email): add a shared transactional delivery outbox feat(jobs): enqueue pg-boss jobs in application transactions Nov 23, 2026
Signed-off-by: Theo Siemens-Rhodes <112789743+theosiemensrhodes@users.noreply.github.com>
Signed-off-by: Theo Siemens-Rhodes <112789743+theosiemensrhodes@users.noreply.github.com>
Signed-off-by: Theo Siemens-Rhodes <112789743+theosiemensrhodes@users.noreply.github.com>
Signed-off-by: Theo Siemens-Rhodes <112789743+theosiemensrhodes@users.noreply.github.com>
@theosiemensrhodes
theosiemensrhodes merged commit 41b89f8 into main Nov 23, 2026
@theosiemensrhodes
theosiemensrhodes deleted the feat/transactional-email-outbox branch November 23, 2026 22:33
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.

1 participant