Skip to content

Commit f08822f

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 822a883 commit f08822f

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
@@ -1563,7 +1563,14 @@ async function provisionResources<B extends Bindings>(
15631563
input.eventSources
15641564
? Promise.all(
15651565
input.eventSources.map(async (eventSource) => {
1566-
return await QueueConsumer(`${eventSource.queue.id}-consumer`, {
1566+
// In local dev mode, queue.id is "" (no Cloudflare API call).
1567+
// Use queue.dev.id (resource ID, e.g. "email-queue") to avoid
1568+
// all consumers colliding on the same "-consumer" resource ID.
1569+
// See: https://github.com/alchemy-run/alchemy/issues/1363
1570+
const queueConsumerId = options.local
1571+
? eventSource.queue.dev?.id || eventSource.queue.id
1572+
: eventSource.queue.id;
1573+
return await QueueConsumer(`${queueConsumerId}-consumer`, {
15671574
queue: eventSource.queue,
15681575
scriptName: options.name,
15691576
settings: eventSource.settings,

0 commit comments

Comments
 (0)