Repository navigation
fix(events): enqueue shift and coverage jobs atomically in transactions - #220
Draft
theosiemensrhodes wants to merge 1 commit into
Draft
theosiemensrhodes wants to merge 1 commit into
theosiemensrhodes wants to merge 1 commit into
Conversation
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.
Summary
Shift creation, shift cancellation, and coverage mutations previously committed domain state before fire-and-forget notification or scheduled-job enqueue calls (
void jobService.run(...)/void notificationEventService.notify*(...)). An enqueue failure or process crash could leave committed domain changes without reminders or notifications, and retrying a shift cancellation returned early oncecanceled = truewas already persisted.This stacked PR builds directly on
feat/transactional-email-outbox(#209) and its transactionalpg-bossenqueueing (JobService.run(..., { transaction })andJobService.cancelPending(..., { transaction })) without introducing a competing outbox table or migration:NotificationService,NotificationEventService,NotifyParams):transactionthroughNotificationEventServicereads/writes andNotificationService.notify(...)intoJobService.run("jobs.process-notification", ..., { transaction, singletonKey, idempotencyKey }).cancelPendingsupport for withdrawn coverage request notifications.coverage.filled/coverage.filled-personalidempotency keys by(coverageRequestId, requestingVolunteerUserId, coveredByVolunteerUserId)so unassigning and re-fulfilling a coverage request still delivers notifications for the new fulfillment while retries remain idempotent.ShiftService,check-shift-notifications.job.ts,process-notification.job.ts):createShiftalways executes inside a PostgreSQL transaction (caller-providedtxforClassService.publishClass, or a new transaction for standalone calls) and atomically enqueues delayedjobs.check-shift-notifications(reminder/no-checkin) jobs with deterministicidempotencyKeyandsingletonKey.cancelShiftlocks theshiftrowFOR UPDATE, updates cancellation state, cancels pending reminder/no-checkin jobs, and enqueues theshift.cancellednotification job in one transaction.deleteShiftdeletes the shift and cancels pending reminder/no-checkin jobs atomically.checkShiftNotificationsJobandprocessNotificationJobhonor cooperative cancellation (isCancelled) and run check reads + notification enqueue in a transaction.CoverageService):createCoverageRequestvalidates shift eligibility, inserts the request, and enqueuescoverage.requested+coverage.availablejobs in one transaction.cancelCoverageRequestlocks the requestFOR UPDATE, marks it withdrawn, and cancels pendingcoverage.requested/coverage.availablejobs atomically.fulfillCoverageRequestlocks the requestFOR UPDATE, checks shift roster assignment within the same transaction, resolves the request, and enqueuescoverage.filled+coverage.filled-personaljobs atomically.unassignCoveragelocks the requestFOR UPDATEand reopens it atomically.Delivery Semantics
pg-bossjob intent commit or roll back atomically in one transaction.FOR UPDATE), deterministic nativepg-bossjob IDs (idempotencyKey), andnotification.idempotencyKeyconflict handling.jobs.send-email) cannot be atomic with PostgreSQL job completion and remains explicitly at-least-once.Dependencies
feat/transactional-email-outbox, headd872f1ec).Validation
SKIP_ENV_VALIDATION=1 pnpm exec next typegen && pnpm typecheck(tsc --noEmit): passedSKIP_ENV_VALIDATION=1 pnpm build: passedpnpm exec prettier --checkon all touched files: passedpnpm test:run) against an isolated disposable PostgreSQL database (neuron_test_n07_7f0e56d2, dropped after run): 12 test files, 131 tests passed, including new failure-injection integration tests insrc/test/integration/durable-domain-events.test.tscovering:cancelShift,createShift,classService.publishClass,createCoverageRequest,fulfillCoverageRequest; transactional job cancellation oncancelShift,deleteShift,cancelCoverageRequest; concurrent fulfillment serialization; unassign + re-fulfill)check-shift-notificationsretry + attendance/coverage-swap handling, idempotent re-execution)pnpm lint/eslintremains blocked by the pre-existing Next 16 / ESLint flat-config incompatibility in this repository (unchanged by this PR).