Skip to content

Commit

Permalink
Improve listing of queues and update API types (#4426)
Browse files Browse the repository at this point in the history
  • Loading branch information
OilyLime authored Dec 18, 2023
1 parent 98dee93 commit c628de5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-sloths-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Improve queues list displaying as table, update queues API types
35 changes: 31 additions & 4 deletions packages/wrangler/src/__tests__/queues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,67 @@ describe("wrangler", () => {
it("should list queues on page 1 with no --page", async () => {
const expectedQueues: QueueResponse[] = [
{
queue_id: "5e1b9969eb974d8c99c48d19df104c7a",
queue_name: "queue-1",
created_on: "01-01-2001",
modified_on: "01-01-2001",
producers: [],
producers_total_count: 0,
consumers: [],
consumers_total_count: 0,
},
{
queue_id: "def19fa3787741579c9088eb850474af",
queue_name: "queue-2",
created_on: "01-01-2001",
modified_on: "01-01-2001",
producers: [],
producers_total_count: 0,
consumers: [],
consumers_total_count: 0,
},
];
const expectedPage = 1;
mockListRequest(expectedQueues, expectedPage);
await runWrangler("queues list");

expect(std.err).toMatchInlineSnapshot(`""`);
const buckets = JSON.parse(std.out);
expect(buckets).toEqual(expectedQueues);
expect(std.out).toMatchInlineSnapshot(`
"┌──────────────────────────────────┬─────────┬────────────┬─────────────┬───────────┬───────────┐
│ id │ name │ created_on │ modified_on │ producers │ consumers │
├──────────────────────────────────┼─────────┼────────────┼─────────────┼───────────┼───────────┤
│ 5e1b9969eb974d8c99c48d19df104c7a │ queue-1 │ 01-01-2001 │ 01-01-2001 │ 0 │ 0 │
├──────────────────────────────────┼─────────┼────────────┼─────────────┼───────────┼───────────┤
│ def19fa3787741579c9088eb850474af │ queue-2 │ 01-01-2001 │ 01-01-2001 │ 0 │ 0 │
└──────────────────────────────────┴─────────┴────────────┴─────────────┴───────────┴───────────┘"
`);
});

it("should list queues using --page=2", async () => {
const expectedQueues: QueueResponse[] = [
{
queue_id: "7f7c2df28cee49ad-bbb46c9e5426e850",
queue_name: "queue-100",
created_on: "01-01-2001",
modified_on: "01-01-2001",
producers: [],
producers_total_count: 0,
consumers: [],
consumers_total_count: 0,
},
];
const expectedPage = 2;
mockListRequest(expectedQueues, expectedPage);
await runWrangler("queues list --page=2");

expect(std.err).toMatchInlineSnapshot(`""`);
const buckets = JSON.parse(std.out);
expect(buckets).toEqual(expectedQueues);
expect(std.out).toMatchInlineSnapshot(`
"┌───────────────────────────────────┬───────────┬────────────┬─────────────┬───────────┬───────────┐
│ id │ name │ created_on │ modified_on │ producers │ consumers │
├───────────────────────────────────┼───────────┼────────────┼─────────────┼───────────┼───────────┤
│ 7f7c2df28cee49ad-bbb46c9e5426e850 │ queue-100 │ 01-01-2001 │ 01-01-2001 │ 0 │ 0 │
└───────────────────────────────────┴───────────┴────────────┴─────────────┴───────────┴───────────┘"
`);
});
});

Expand Down
11 changes: 10 additions & 1 deletion packages/wrangler/src/queues/cli/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@ export async function handler(
const config = readConfig(args.config, args);

const queues = await listQueues(config, args.page);
logger.log(JSON.stringify(queues));
logger.table(
queues.map((queue) => ({
id: queue.queue_id,
name: queue.queue_name,
created_on: queue.created_on,
modified_on: queue.modified_on,
producers: queue.producers_total_count.toString(),
consumers: queue.consumers_total_count.toString(),
}))
);
}
20 changes: 20 additions & 0 deletions packages/wrangler/src/queues/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,30 @@ export interface CreateQueueBody {
queue_name: string;
}

export interface ScriptReference {
namespace?: string;
script?: string;
service?: string;
environment?: string;
}

export type Consumer = ScriptReference & {
dead_letter_queue?: string;
settings: ConsumerSettings;
consumer_id: string;
bucket_name?: string;
type: string;
};

export interface QueueResponse {
queue_id: string;
queue_name: string;
created_on: string;
modified_on: string;
producers: ScriptReference[];
producers_total_count: number;
consumers: Consumer[];
consumers_total_count: number;
}

export async function deleteQueue(
Expand Down

0 comments on commit c628de5

Please sign in to comment.