fix(queue): let a shut-down queue be started again

`shutdown()` set `accepting = false` and `start()` refused for ever after, so
a queue was single-use. Any process that boots more than one app broke: a test
suite closing one harness and opening the next, a hot reload, a multi-tenant
host. The failure landed far from its cause -- the SECOND app to boot threw
WRN-QUEUE-CLOSED out of the dev server because an unrelated one had shut down
earlier in the same process. That is what turned six example-app security
tests red only when run alongside the rest of the suite.

Starting is an explicit intent to run, so it reopens the queue. `add()` keeps
its guard, so work offered to a queue that is shutting down is still refused.

Also migrates the example app's welcome-email queue to `defineQueue`, which
the new loader requires. It still used `defineJob`, so the loader refused it
and took the whole example app down -- 14 failures from one unmigrated file.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-23 11:36:44 +05:30
co-authored by Claude Opus 5
parent 64ab20cc95
commit d87b197224
3 changed files with 60 additions and 5 deletions
+12 -1
View File
@@ -357,7 +357,18 @@ export function createDurableQueue(options: DurableQueueOptions = {}): DurableQu
},
start() {
if (!accepting) throw new Error("WRN-QUEUE-CLOSED: queue is shutting down");
/*
* Starting is an explicit intent to run, so it reopens a queue that was
* shut down rather than refusing for ever. Without this a queue is
* single-use, which breaks any process that boots more than one app --
* a test suite closing one harness and opening the next, a hot reload,
* a multi-tenant host. The failure lands far from its cause: the SECOND
* app to boot throws, because an unrelated one shut down earlier.
*
* `add()` keeps its guard, so work offered to a queue that is shutting
* down is still refused until someone deliberately starts it again.
*/
accepting = true;
if (timer) return;
timer = setInterval(() => {
void this.drain().catch(async (error: unknown) => {