()
| 85 | * still in the queue and gets drained on the next tick. |
| 86 | */ |
| 87 | export function kickDrainAfterResponse(): void { |
| 88 | const cronSecret = process.env.CRON_SECRET; |
| 89 | if (!cronSecret) { |
| 90 | // In dev without CRON_SECRET we silently skip the kick. The drain route |
| 91 | // would 500 anyway (requireCronAuth fail-closes when CRON_SECRET is unset). |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | after(async () => { |
| 96 | try { |
| 97 | await fetch(`${drainBaseUrl()}${DRAIN_PATH}`, { |
| 98 | headers: { Authorization: `Bearer ${cronSecret}` }, |
| 99 | }); |
| 100 | } catch (err) { |
| 101 | // Best-effort kick; the cron will retry. Logging keeps us honest about |
| 102 | // how often the kick path fails so we can spot regressions. |
| 103 | console.error("[queue] kick drain failed (cron will retry)", err); |
| 104 | } |
| 105 | }); |
| 106 | } |
no test coverage detected