Skip to content

Commit

Permalink
fix(wrangler): [Queues] Output suggested wrangler.toml changes after …
Browse files Browse the repository at this point in the history
…creating a queue (#7191)
  • Loading branch information
sdnts authored Nov 7, 2024
1 parent f6879d3 commit 1d5bc6d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-pigs-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Output suggested wrangler.toml changes after creating a Queue
32 changes: 27 additions & 5 deletions packages/wrangler/src/__tests__/queues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,19 @@ describe("wrangler", () => {
const requests = mockCreateRequest("testQueue");
await runWrangler("queues create testQueue");
expect(std.out).toMatchInlineSnapshot(`
"Creating queue testQueue.
Created queue testQueue."
"🌀 Creating queue 'testQueue'
✅ Created queue 'testQueue'
Configure your Worker to send messages to this queue:
[[queues.producers]]
queue = \\"testQueue\\"
binding = \\"testQueue\\"
Configure your Worker to consume messages from this queue:
[[queues.consumers]]
queue = \\"testQueue\\""
`);
expect(requests.count).toEqual(1);
});
Expand Down Expand Up @@ -290,7 +301,7 @@ describe("wrangler", () => {
runWrangler(`queues create ${queueName}`)
).rejects.toThrowError();
expect(std.out).toMatchInlineSnapshot(`
"Creating queue testQueue.
"🌀 Creating queue 'testQueue'
Queues is not currently enabled on this account. Go to https://dash.cloudflare.com/some-account-id/workers/queues to enable it.
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/queues) failed.
Expand All @@ -308,8 +319,19 @@ describe("wrangler", () => {
const requests = mockCreateRequest("testQueue", { delivery_delay: 10 });
await runWrangler("queues create testQueue --delivery-delay-secs=10");
expect(std.out).toMatchInlineSnapshot(`
"Creating queue testQueue.
Created queue testQueue."
"🌀 Creating queue 'testQueue'
✅ Created queue 'testQueue'
Configure your Worker to send messages to this queue:
[[queues.producers]]
queue = \\"testQueue\\"
binding = \\"testQueue\\"
Configure your Worker to consume messages from this queue:
[[queues.consumers]]
queue = \\"testQueue\\""
`);
expect(requests.count).toEqual(1);
});
Expand Down
14 changes: 12 additions & 2 deletions packages/wrangler/src/queues/cli/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readConfig } from "../../../config";
import { CommandLineArgsError } from "../../../errors";
import { logger } from "../../../logger";
import { getValidBindingName } from "../../../utils/getValidBindingName";
import { createQueue } from "../../client";
import { handleFetchError } from "../../utils";
import type {
Expand Down Expand Up @@ -53,9 +54,18 @@ export async function handler(
const config = readConfig(args.config, args);
const body = createBody(args);
try {
logger.log(`Creating queue ${args.name}.`);
logger.log(`🌀 Creating queue '${args.name}'`);
await createQueue(config, body);
logger.log(`Created queue ${args.name}.`);
logger.log(
`✅ Created queue '${args.name}'\n\n` +
"Configure your Worker to send messages to this queue:\n\n" +
"[[queues.producers]]\n" +
`queue = "${args.name}"\n` +
`binding = "${getValidBindingName(args.name, "queue")}"\n\n` +
"Configure your Worker to consume messages from this queue:\n\n" +
"[[queues.consumers]]\n" +
`queue = "${args.name}"`
);
} catch (e) {
handleFetchError(e as { code?: number });
}
Expand Down

0 comments on commit 1d5bc6d

Please sign in to comment.