Skip to content

Add background job that scans for booking-intents stuck in "pending_payment" > 30 min and cancels them #588

Description

@thlpkee20-wq

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

Metadata

Metadata

Labels

Stellar WaveStellar Wave issue batchbackendBackend scopedatabaseMigrations, queries, pooling, transactionsfeatureNew feature work

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions