Skip to content

Commit 6b4972a

Browse files
committed
wrangler: accept and display Queue jurisdiction metadata
1 parent ad00f44 commit 6b4972a

5 files changed

Lines changed: 134 additions & 10 deletions

File tree

.changeset/tall-queens-matter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Add support for jurisdictions to Queues subcommands

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,57 @@ describe("wrangler", () => {
190190
└─┴─┴─┴─┴─┴─┘"
191191
`);
192192
});
193+
194+
it("should list queues' jurisdictions, if present", async ({
195+
expect,
196+
}) => {
197+
const expectedQueues: QueueResponse[] = [
198+
{
199+
queue_id: "5e1b9969eb974d8c99c48d19df104c7a",
200+
queue_name: "queue-1",
201+
created_on: "01-01-2001",
202+
modified_on: "01-01-2001",
203+
producers: [],
204+
producers_total_count: 0,
205+
consumers: [],
206+
consumers_total_count: 0,
207+
settings: {
208+
delivery_delay: 0,
209+
},
210+
},
211+
{
212+
queue_id: "def19fa3787741579c9088eb850474af",
213+
queue_name: "queue-2",
214+
jurisdiction: "eu",
215+
created_on: "01-01-2001",
216+
modified_on: "01-01-2001",
217+
producers: [],
218+
producers_total_count: 0,
219+
consumers: [],
220+
consumers_total_count: 0,
221+
settings: {
222+
delivery_delay: 0,
223+
},
224+
},
225+
];
226+
const expectedPage = 1;
227+
mockListRequest(expect, expectedQueues, expectedPage);
228+
await runWrangler("queues list");
229+
230+
expect(std.err).toMatchInlineSnapshot(`""`);
231+
expect(std.out).toMatchInlineSnapshot(`
232+
"
233+
⛅️ wrangler x.x.x
234+
──────────────────
235+
┌─┬─┬─┬─┬─┬─┬─┐
236+
│ id │ name │ jurisdiction │ created_on │ modified_on │ producers │ consumers │
237+
├─┼─┼─┼─┼─┼─┼─┤
238+
│ 5e1b9969eb974d8c99c48d19df104c7a │ queue-1 │ │ 01-01-2001 │ 01-01-2001 │ 0 │ 0 │
239+
├─┼─┼─┼─┼─┼─┼─┤
240+
│ def19fa3787741579c9088eb850474af │ queue-2 │ eu │ 01-01-2001 │ 01-01-2001 │ 0 │ 0 │
241+
└─┴─┴─┴─┴─┴─┴─┘"
242+
`);
243+
});
193244
});
194245

195246
describe("create", () => {
@@ -257,6 +308,7 @@ describe("wrangler", () => {
257308
-v, --version Show version number [boolean]
258309
259310
OPTIONS
311+
--jurisdiction The jurisdiction of the queue [string] [choices: "eu", "us", "fedramp"]
260312
--delivery-delay-secs How long a published message should be delayed for, in seconds. Must be between 0 and 86400 [number]
261313
--message-retention-period-secs How long to retain a message in the queue, in seconds. Must be between 60 and 86400 if on free tier, otherwise must be between 60 and 1209600 [number]"
262314
`);
@@ -2475,6 +2527,31 @@ describe("wrangler", () => {
24752527
-v, --version Show version number [boolean]"
24762528
`);
24772529
});
2530+
2531+
it("should return queue info with jurisdiction, if present", async ({
2532+
expect,
2533+
}) => {
2534+
mockGetQueueByNameRequest(expectedQueueName, {
2535+
...mockQueue,
2536+
jurisdiction: "eu",
2537+
});
2538+
await runWrangler("queues info testQueue");
2539+
expect(std.out).toMatchInlineSnapshot(`
2540+
"
2541+
⛅️ wrangler x.x.x
2542+
──────────────────
2543+
Queue Name: testQueue
2544+
Queue ID: 1234567
2545+
Jurisdiction: eu
2546+
Created On: 2024-05-20T14:43:56.70498Z
2547+
Last Modified: 2024-07-19T14:43:56.70498Z
2548+
Number of Producers: 2
2549+
Producers: worker:test-producer1, worker:test-producer2
2550+
Number of Consumers: 1
2551+
Consumers: worker:test-consumer"
2552+
`);
2553+
});
2554+
24782555
it("should return queue info with worker producers when the queue has workers configured as producers", async ({
24792556
expect,
24802557
}) => {
@@ -2494,6 +2571,7 @@ describe("wrangler", () => {
24942571
Consumers: worker:test-consumer"
24952572
`);
24962573
});
2574+
24972575
it('should return "http consumer" and a curl command when the consumer type is http_pull', async ({
24982576
expect,
24992577
}) => {

packages/wrangler/src/queues/cli/commands/create.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "../../constants";
1616
import { handleFetchError } from "../../utils";
1717
import type { PostQueueBody } from "../../client";
18+
import type { QueueJurisdiction } from "@cloudflare/deploy-helpers";
1819

1920
export const queuesCreateCommand = createCommand({
2021
metadata: {
@@ -29,6 +30,11 @@ export const queuesCreateCommand = createCommand({
2930
demandOption: true,
3031
description: "The name of the queue",
3132
},
33+
jurisdiction: {
34+
type: "string",
35+
describe: "The jurisdiction of the queue",
36+
choices: ["eu", "us", "fedramp"],
37+
},
3238
"delivery-delay-secs": {
3339
type: "number",
3440
describe: `How long a published message should be delayed for, in seconds. Must be between ${MIN_DELIVERY_DELAY_SECS} and ${MAX_DELIVERY_DELAY_SECS}`,
@@ -86,6 +92,7 @@ export const queuesCreateCommand = createCommand({
8692
function createBody(args: typeof queuesCreateCommand.args): PostQueueBody {
8793
const body: PostQueueBody = {
8894
queue_name: args.name,
95+
jurisdiction: args.jurisdiction as QueueJurisdiction,
8996
};
9097

9198
body.settings = {};

packages/wrangler/src/queues/cli/commands/info.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export const queuesInfoCommand = createCommand({
2525

2626
logger.log(`Queue Name: ${queue.queue_name}`);
2727
logger.log(`Queue ID: ${queue.queue_id}`);
28+
if (queue.jurisdiction !== undefined) {
29+
logger.log(`Jurisdiction: ${queue.jurisdiction}`);
30+
}
2831
logger.log(`Created On: ${queue.created_on}`);
2932
logger.log(`Last Modified: ${queue.modified_on}`);
3033
logger.log(`Number of Producers: ${queue.producers_total_count}`);

packages/wrangler/src/queues/cli/commands/list.ts

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,46 @@ export const queuesListCommand = createCommand({
1717
},
1818
async handler(args, { config }) {
1919
const queues = await listQueues(config, args.page);
20-
logger.table(
21-
queues.map((queue) => ({
22-
id: queue.queue_id,
23-
name: queue.queue_name,
24-
created_on: queue.created_on,
25-
modified_on: queue.modified_on,
26-
producers: queue.producers_total_count.toString(),
27-
consumers: queue.consumers_total_count.toString(),
28-
}))
29-
);
20+
21+
// A few behaviours we want necessitates this obtuse-looking code:
22+
//
23+
// 1. We'd like to hide the `jurisdiction` column entirely if and only if none of the Queues
24+
// are jurisdictional. The table logger will do this for us if none of the objects we pass
25+
// to it have a `jurisdiction` property.
26+
//
27+
// 2. The table logger calculates which columns to print out by looking at the _first_ object
28+
// passed to it. We'd like to make sure the `jurisdiction` column is definitely printed out
29+
// if any Queue is in a jurisdiction.
30+
//
31+
// 3. We'd like for this `jurisdiction` column (if present) to show up next to the queue name.
32+
// The table logger prints columns out in the order properties are set on the _first_ object.
33+
// Technically JS does not guarantee property ordering in objects, but in practice it often
34+
// works out that way.
35+
36+
const hasJurisdictions = queues.some((q) => q.jurisdiction !== undefined);
37+
if (hasJurisdictions) {
38+
logger.table(
39+
queues.map((q) => ({
40+
id: q.queue_id,
41+
name: q.queue_name,
42+
jurisdiction: q.jurisdiction ?? "",
43+
created_on: q.created_on,
44+
modified_on: q.modified_on,
45+
producers: q.producers_total_count.toString(),
46+
consumers: q.consumers_total_count.toString(),
47+
}))
48+
);
49+
} else {
50+
logger.table(
51+
queues.map((q) => ({
52+
id: q.queue_id,
53+
name: q.queue_name,
54+
created_on: q.created_on,
55+
modified_on: q.modified_on,
56+
producers: q.producers_total_count.toString(),
57+
consumers: q.consumers_total_count.toString(),
58+
}))
59+
);
60+
}
3061
},
3162
});

0 commit comments

Comments
 (0)