Skip to content

Commit e6c94ab

Browse files
committed
fix(cloudflare): use queue dev.id for consumer resource ID in local dev mode
In local dev mode, Queue resources return an empty string for `id` (Cloudflare API ID) since no remote API call is made. When a Worker has multiple eventSources, all QueueConsumers were derived as `${queue.id}-consumer` which all resolved to "-consumer", causing concurrent Promise.all writes to the same state file. This led to corrupted JSON state files and silently broken queue consumers — the Worker HTTP endpoint would respond normally but queue messages were never consumed. Fix: use `queue.dev.id` (the resource ID, e.g. "email-queue") in local dev mode, which is always unique per queue. Fixes #1363
1 parent dc33580 commit e6c94ab

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

alchemy/src/cloudflare/worker.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,14 @@ async function provisionResources<B extends Bindings>(
13631363
input.eventSources
13641364
? Promise.all(
13651365
input.eventSources.map(async (eventSource) => {
1366-
return await QueueConsumer(`${eventSource.queue.id}-consumer`, {
1366+
// Use dev.id (resource ID, e.g. "email-queue") in local dev mode
1367+
// instead of queue.id (Cloudflare API ID, empty "" in dev mode).
1368+
// Without this, all consumers collide on the same resource ID "-consumer",
1369+
// causing concurrent writes to the same state file.
1370+
const queueId = options.local
1371+
? (eventSource.queue.dev?.id || eventSource.queue.id)
1372+
: eventSource.queue.id;
1373+
return await QueueConsumer(`${queueId}-consumer`, {
13671374
queue: eventSource.queue,
13681375
scriptName: options.name,
13691376
settings: eventSource.settings,

0 commit comments

Comments
 (0)