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:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user