Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42aafa3

Browse files
fix(wrangler) remove putQueue call when deploying a worker with queue producer binding (#10288)
* MQ-861: Remove putQueue call when setting queue producer binding * remove calls to mockPutQueueById in tests * Update .changeset/chatty-pens-sniff.md Co-authored-by: Pete Bacon Darwin <[email protected]> * try to ensure that the required deploy workers job is not skipped * test: add a waitFor around log check for email bindings --------- Co-authored-by: Pete Bacon Darwin <[email protected]> Co-authored-by: Peter Bacon Darwin <[email protected]>
1 parent a4c4c5b commit 42aafa3

File tree

6 files changed

+25
-83
lines changed

6 files changed

+25
-83
lines changed

.changeset/chatty-pens-sniff.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Do not attempt to update queue producer settings when deploying a Worker with a queue binding
6+
7+
Previously, each deployed Worker would update a subset of the queue producer's settings for each queue binding, which could result in broken queue producers or at least conflicts where different Workers tried to set different producer settings on a shared queue.

.github/workflows/c3-e2e.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
deploy-test-workers:
1515
name: Deploy Test Workers
1616
runs-on: ubuntu-latest
17-
if: github.event.pull_request.head.repo.owner.login == 'cloudflare' || github.event_name == 'merge_group'
1817
steps:
1918
- name: Checkout Repo
2019
uses: actions/checkout@v4
@@ -39,7 +38,7 @@ jobs:
3938
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
4039

4140
- name: Deploy test workers
42-
if: steps.changes.outputs.everything_but_markdown == 'true'
41+
if: github.event.pull_request.head.repo.owner.login == 'cloudflare' && steps.changes.outputs.everything_but_markdown == 'true'
4342
shell: bash
4443
run: node -r esbuild-register tools/test-workers/deploy-all.ts
4544
env:

packages/miniflare/test/plugins/email/index.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ test("Unbound send_email binding works", async (t) => {
7575
);
7676
t.is(await res.text(), "ok");
7777
t.is(res.status, 200);
78-
t.true(
79-
log.logs.some(
80-
([type, message]) =>
81-
type === LogLevel.INFO &&
82-
message.includes(
83-
"send_email binding called with the following message:"
84-
)
78+
waitFor(async () =>
79+
t.true(
80+
log.logs.some(
81+
([type, message]) =>
82+
type === LogLevel.INFO &&
83+
message.includes(
84+
"send_email binding called with the following message:"
85+
)
86+
)
8587
)
8688
);
8789

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ import { writeWranglerConfig } from "./helpers/write-wrangler-config";
5858
import type { AssetManifest } from "../assets";
5959
import type { Config } from "../config";
6060
import type { CustomDomain, CustomDomainChangeset } from "../deploy/deploy";
61-
import type {
62-
PostQueueBody,
63-
PostTypedConsumerBody,
64-
QueueResponse,
65-
} from "../queues/client";
61+
import type { PostTypedConsumerBody, QueueResponse } from "../queues/client";
6662
import type { FormData } from "undici";
6763
import type { Mock } from "vitest";
6864

@@ -11443,10 +11439,6 @@ export default{
1144311439
modified_on: "",
1144411440
};
1144511441
mockGetQueueByName(queueName, existingQueue);
11446-
mockPutQueueById(queueId, {
11447-
queue_name: queueName,
11448-
settings: {},
11449-
});
1145011442

1145111443
await runWrangler("deploy index.js");
1145211444
expect(std.out).toMatchInlineSnapshot(`
@@ -11490,12 +11482,7 @@ export default{
1149011482
modified_on: "",
1149111483
};
1149211484
mockGetQueueByName(queueName, existingQueue);
11493-
mockPutQueueById(queueId, {
11494-
queue_name: queueName,
11495-
settings: {
11496-
delivery_delay: 10,
11497-
},
11498-
});
11485+
1149911486
await runWrangler("deploy index.js");
1150011487
expect(std.out).toMatchInlineSnapshot(`
1150111488
"Total Upload: xx KiB / gzip: xx KiB
@@ -13651,37 +13638,6 @@ function mockPostConsumerById(
1365113638
return requests;
1365213639
}
1365313640

13654-
function mockPutQueueById(
13655-
expectedQueueId: string,
13656-
expectedBody: PostQueueBody
13657-
) {
13658-
const requests = { count: 0 };
13659-
msw.use(
13660-
http.put(
13661-
`*/accounts/:accountId/queues/:queueId`,
13662-
async ({ request, params }) => {
13663-
const body = await request.json();
13664-
expect(params.queueId).toEqual(expectedQueueId);
13665-
expect(params.accountId).toEqual("some-account-id");
13666-
expect(body).toEqual(expectedBody);
13667-
requests.count += 1;
13668-
return HttpResponse.json({
13669-
success: true,
13670-
errors: [],
13671-
messages: [],
13672-
result: {
13673-
queue: expectedBody.queue_name,
13674-
settings: {
13675-
delivery_delay: expectedBody.settings?.delivery_delay,
13676-
},
13677-
},
13678-
});
13679-
}
13680-
)
13681-
);
13682-
return requests;
13683-
}
13684-
1368513641
function mockPostQueueHTTPConsumer(
1368613642
expectedQueueId: string,
1368713643
expectedBody: PostTypedConsumerBody

packages/wrangler/src/deploy/deploy.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import {
3939
postConsumer,
4040
putConsumer,
4141
putConsumerById,
42-
putQueue,
4342
} from "../queues/client";
4443
import { syncWorkersSite } from "../sites";
4544
import {
@@ -72,7 +71,7 @@ import type {
7271
CfWorkerInit,
7372
} from "../deployment-bundle/worker";
7473
import type { ComplianceConfig } from "../environment-variables/misc-variables";
75-
import type { PostQueueBody, PostTypedConsumerBody } from "../queues/client";
74+
import type { PostTypedConsumerBody } from "../queues/client";
7675
import type { LegacyAssetPaths } from "../sites";
7776
import type { RetrieveSourceMapFunction } from "../sourcemap";
7877
import type { ApiVersion, Percentage, VersionId } from "../versions/types";
@@ -1260,29 +1259,6 @@ export function isAuthenticationError(e: unknown): e is ParseError {
12601259
return e instanceof ParseError && (e as { code?: number }).code === 10000;
12611260
}
12621261

1263-
export async function updateQueueProducers(
1264-
config: Config
1265-
): Promise<Promise<string[]>[]> {
1266-
const producers = config.queues.producers || [];
1267-
const updateProducers: Promise<string[]>[] = [];
1268-
for (const producer of producers) {
1269-
const body: PostQueueBody = {
1270-
queue_name: producer.queue,
1271-
settings: {
1272-
delivery_delay: producer.delivery_delay,
1273-
},
1274-
};
1275-
1276-
updateProducers.push(
1277-
putQueue(config, producer.queue, body).then(() => [
1278-
`Producer for ${producer.queue}`,
1279-
])
1280-
);
1281-
}
1282-
1283-
return updateProducers;
1284-
}
1285-
12861262
export async function updateQueueConsumers(
12871263
scriptName: string | undefined,
12881264
config: Config

packages/wrangler/src/triggers/deploy.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
publishRoutes,
88
renderRoute,
99
updateQueueConsumers,
10-
updateQueueProducers,
1110
validateRoutes,
1211
} from "../deploy/deploy";
1312
import { UserError } from "../errors";
@@ -279,8 +278,11 @@ export default async function triggersDeploy(
279278
}
280279

281280
if (config.queues.producers && config.queues.producers.length) {
282-
const updateProducers = await updateQueueProducers(config);
283-
deployments.push(...updateProducers);
281+
deployments.push(
282+
...config.queues.producers.map((producer) =>
283+
Promise.resolve([`Producer for ${producer.queue}`])
284+
)
285+
);
284286
}
285287

286288
if (config.queues.consumers && config.queues.consumers.length) {

0 commit comments

Comments
 (0)