Repository navigation
feat(jobs): enqueue pg-boss jobs in application transactions - #209
Merged
Merged
Conversation
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>
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.
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.