Skip to content

MQ-1242: Removing a consumer from Wrangler config should detach that consumer#13923

Draft
tgarg-cf wants to merge 2 commits into
cloudflare:mainfrom
tgarg-cf:tgarg/MQ-1242_call_Script_Consumers_endpoint_when_deploying_worker
Draft

MQ-1242: Removing a consumer from Wrangler config should detach that consumer#13923
tgarg-cf wants to merge 2 commits into
cloudflare:mainfrom
tgarg-cf:tgarg/MQ-1242_call_Script_Consumers_endpoint_when_deploying_worker

Conversation

@tgarg-cf
Copy link
Copy Markdown
Contributor

@tgarg-cf tgarg-cf commented May 14, 2026

Fixes https://jira.cfdata.org/browse/MQ-1242

Describe your change...

wrangler deploy now cleans up stale queue consumer registrations.

Previously, when a user removed a queue consumer from their wrangler.json config and redeployed, Wrangler left the old consumer registration in place — the worker continued receiving messages from a queue it no longer declared. This was because deploy only ever called the create/update consumer endpoints for the consumers currently in the config list.

This PR replaces the per-consumer create/update calls with a single declarative call to EWC's new script-level endpoint (PUT /accounts/{accountId}/workers/scripts/{scriptName}/queue-consumers). Wrangler sends the full, authoritative list of declared consumers, and EWC creates, updates, or deletes registrations as needed.

The endpoint is called on every deploy (not just when consumers are declared) so stale registrations get cleaned up even if the user removes the entire queues section. This has to be done as wrangler doesn't track diffs between deploys but the cost for non-queue workers is a cheap no-op call to EWC per deploy.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because:

A picture of a cute animal (not mandatory, but encouraged)

tgarg-cf added 2 commits May 14, 2026 15:59
`wrangler deploy` now sends the full list of declared queue consumers to a single script-level EWC endpoint, removing stale consumer registrations when a consumer is removed from the config. The per-consumer outcome (created/updated/removed/failed) is reported inline with the rest of the trigger summary. If a consumer fails to configure, the error is printed and the deploy exits with a non-zero status without aborting other trigger deployments.
…ndpoint

Updates queue consumer deployment tests to use `mockSetScriptConsumers` instead of individual `mockPostConsumerById` and `mockPutQueueConsumerById` mocks, reflecting the new script-level queue consumer configuration endpoint. Adds test coverage for multiple consumers in a single request and updates assertions to match the new API response format.
@tgarg-cf tgarg-cf requested a review from workers-devprod as a code owner May 14, 2026 20:10
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 14, 2026

🦋 Changeset detected

Latest commit: bcc51d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk May 14, 2026
@workers-devprod workers-devprod requested review from a team and jamesopstad and removed request for a team May 14, 2026 20:10
@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/clean-up-stale-queue-consumers-on-deploy.md: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/deploy/helpers.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/deploy/queues.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/helpers/msw/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deploy/deploy.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/queues/client.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/triggers/deploy.ts: [@cloudflare/wrangler]

@tgarg-cf tgarg-cf marked this pull request as draft May 14, 2026 20:13
@tgarg-cf tgarg-cf changed the title Tgarg/mq 1242 call script consumers endpoint when deploying worker MQ-1242: Removing a consumer from Wrangler config should detach that consumer May 14, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 14, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13923

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13923

miniflare

npm i https://pkg.pr.new/miniflare@13923

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13923

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13923

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13923

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13923

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13923

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@13923

wrangler

npm i https://pkg.pr.new/wrangler@13923

commit: bcc51d8

}
// Always call so stale consumers from previous deploys are cleaned up,
// even when the user has removed all consumers from their config.
deployments.push(updateQueueConsumers(scriptName, config, queueNameToId));
Copy link
Copy Markdown
Contributor Author

@tgarg-cf tgarg-cf May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context: we want consumers to be cleaned up even if the user has removed the queues section from the wrangler.jsonc.

const targets = await Promise.all(deployments);
const deployMs = Date.now() - start - uploadMs;

if (deployments.length > 0) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are now calling updateQueueConsumers() on every deploy, this check is no longer accurate. Comparing with the flat targets instead

Removed consumer for old-queue
```

If a consumer fails to configure, the error is printed both inline and to stderr, and the deploy exits with a non-zero status without aborting other trigger deployments.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you are saying that the Worker deployment will complete (along with other triggers) but that Wrangler will exit with non-zero status, indicating that it actually failed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if the wrangler team prefers a different behaviour, we are okay with that. I was trying to find the least invasive approach.

Comment on lines +1590 to +1591
logger.error(`Failed to configure queue consumers: ${message}`);
process.exitCode = 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using process.exitCode is a bit awkward. E.g. what does 1 mean? It may be more work but I think if we really want deploy to soft-fail then we should provide a way for the deploy handler to capture a FatalError thrown from this function and continue with the rest of the deployment before "failing" at the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does sound better. Could you give me more direction on what that would look like? We call this function in triggersDeploy (https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/triggers/deploy.ts#L263) and the promises are resolved in https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/triggers/deploy.ts#L306. What should the handler do if it receives an error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants