examplesstorefront Public
Keep expiring orders behind ones left to the webhook #3
- src/expiry.ts line 13
13export const MAX_PER_RUN = 200;-
Justin Torre
A note for later: if an outage ever leaves more than 200 paid orders pending, we are back to the same problem with a bigger number. That is a lot of stuck payments for a shop this size, so I am fine with the cap. If it does happen, the next step is a last_checked_at column so a run skips orders it looked at in the past hour.
-
-
Justin Torre
Checked the plan for the new query against a local copy of the schema: it still uses orders_by_status, and the row value comparison is the same form the catalog cursor already uses on D1.
-
Justin Torre pushed to expire-behind-stuck-orders 8b37e66 → 38a9ec4
Open
Ready to merge
- Successduragit/ci/testsucceededDetails
- No conflictsmain can fast-forward to the head
Sign in to comment.
The expiry cron could stop cancelling abandoned checkouts entirely, and they kept their stock until someone noticed.
Why
Every five minutes
expireOrdersasked D1 for the 50 oldest orders stillpending_paymentpast the 30 minute window. For each one it tries to cancel the PaymentIntent, and when Stripe refuses because the payment already went through, it leaves the order for the webhook to mark paid. That order stayspending_payment, and it stays the oldest.So if the webhook falls behind (a bad deploy of the signing secret, say), paid orders pile up at the front of the query. Once there are 50 of them, every run picks the same 50, leaves all of them to the webhook, and never reaches the abandoned checkouts behind them. Those keep their stock, and products show as sold out while nobody is buying them. It clears up only when Stripe's retries finally get through.
What changed
src/expiry.tspages through the expired orders 50 at a time by(created_at, id), starting each page after the last order it looked at, instead of asking for the oldest 50 again.MAX_PER_RUN), so its calls to Stripe stay bounded. The next run starts from the oldest again.No schema change. The query uses the existing
orders_by_statusindex on(status, created_at).Testing
mainthis test fails: the report lists the 50 and nothing is cancelled.MAX_PER_RUNand the next run picks up the rest.npm test(51 tests) andnpm run typecheckpass.kb checkandarch checkpass.