Description
Add a scheduled worker that finds booking_intents.status = 'pending_payment' AND created_at < now() - 30 min, cancels them, releases the slot inventory, and emits a booking_intent_expired event.
Requirements and context
- Must be secure, tested, and documented
- Should be efficient and easy to review
- Relevant code:
src/workers/expireBookingIntents.ts (new), src/scheduler/registry.ts
Suggested execution
- Fork the repo and create a branch
git checkout -b feat/expire-pending-booking-intents
- Implement changes
- Cron every 60s; use
FOR UPDATE SKIP LOCKED to allow multi-instance
- Update
status='cancelled_expired', emit booking_intent_expired event, decrement slot_reservation counter
- Add prometheus gauge
booking_intents_expired_total
- Validate security and correctness assumptions
Test and commit
- Run tests
npm test (integration with testcontainers pg)
- Cover edge cases
- two workers running (no double-cancel), expiry exactly at 30 min boundary, slot already-completed
- Include test output and notes
Example commit message
feat: expire stale pending-payment booking-intents
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Description
Add a scheduled worker that finds
booking_intents.status = 'pending_payment' AND created_at < now() - 30 min, cancels them, releases the slot inventory, and emits abooking_intent_expiredevent.Requirements and context
src/workers/expireBookingIntents.ts(new),src/scheduler/registry.tsSuggested execution
git checkout -b feat/expire-pending-booking-intentsFOR UPDATE SKIP LOCKEDto allow multi-instancestatus='cancelled_expired', emitbooking_intent_expiredevent, decrementslot_reservationcounterbooking_intents_expired_totalTest and commit
npm test(integration with testcontainers pg)Example commit message
feat: expire stale pending-payment booking-intentsGuidelines