Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fuzzy-dogs-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
Comment thread
dmmulroy marked this conversation as resolved.
Outdated
---

Support Artifacts sources when creating Queue event subscriptions

`wrangler queues subscription create` now accepts the `artifacts` and `artifacts.repo` source types supported by the Cloudflare API.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("queues subscription", () => {
-v, --version Show version number [boolean]

OPTIONS
--source The event source type [string] [required] [choices: "images", "kv", "r2", "superSlurper", "vectorize", "workersAi.model", "workersBuilds.worker", "workflows.workflow"]
--source The event source type [string] [required] [choices: "artifacts", "artifacts.repo", "images", "kv", "r2", "superSlurper", "vectorize", "workersAi.model", "workersBuilds.worker", "workflows.workflow"]
--events Comma-separated list of event types to subscribe to [string] [required]
--name Name for the subscription (auto-generated if not provided) [string]
--enabled Whether the subscription should be active [boolean] [default: true]
Expand Down Expand Up @@ -187,6 +187,76 @@ describe("queues subscription", () => {
`);
});

it("should create a subscription for an Artifacts account source", async ({
expect,
}) => {
const queueNameResolveRequest = mockGetQueueByNameRequest(
expectedQueueName,
{
queue_id: expectedQueueId,
queue_name: expectedQueueName,
created_on: "",
producers: [],
consumers: [],
producers_total_count: 0,
consumers_total_count: 0,
modified_on: "",
}
);

const createRequest = mockCreateSubscriptionRequest(
{
name: "testQueue artifacts",
enabled: true,
source: { type: EventSourceType.ARTIFACTS },
events: ["repo.created"],
},
expectedQueueId
);

await runWrangler(
"queues subscription create testQueue --source artifacts --events repo.created"
);

expect(queueNameResolveRequest.count).toEqual(1);
expect(createRequest.count).toEqual(1);
});

it("should create a subscription for an Artifacts repository source", async ({
expect,
}) => {
const queueNameResolveRequest = mockGetQueueByNameRequest(
expectedQueueName,
{
queue_id: expectedQueueId,
queue_name: expectedQueueName,
created_on: "",
producers: [],
consumers: [],
producers_total_count: 0,
consumers_total_count: 0,
modified_on: "",
}
);

const createRequest = mockCreateSubscriptionRequest(
{
name: "testQueue artifacts.repo",
enabled: true,
source: { type: EventSourceType.ARTIFACTS_REPO },
events: ["pushed"],
},
expectedQueueId
);

await runWrangler(
"queues subscription create testQueue --source artifacts.repo --events pushed"
);

expect(queueNameResolveRequest.count).toEqual(1);
expect(createRequest.count).toEqual(1);
});

it("should create subscription with custom name and disabled state", async ({
expect,
}) => {
Expand Down Expand Up @@ -254,7 +324,7 @@ describe("queues subscription", () => {
)
).rejects.toThrowErrorMatchingInlineSnapshot(`
[Error: Invalid values:
Argument: source, Given: "invalid", Choices: "images", "kv", "r2", "superSlurper", "vectorize", "workersAi.model", "workersBuilds.worker", "workflows.workflow"]
Argument: source, Given: "invalid", Choices: "artifacts", "artifacts.repo", "images", "kv", "r2", "superSlurper", "vectorize", "workersAi.model", "workersBuilds.worker", "workflows.workflow"]
`);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ function parseSourceArgument(
}
): EventSource {
switch (source as EventSourceType) {
case EventSourceType.ARTIFACTS:
return { type: EventSourceType.ARTIFACTS };

case EventSourceType.ARTIFACTS_REPO:
return { type: EventSourceType.ARTIFACTS_REPO };

case EventSourceType.IMAGES:
return { type: EventSourceType.IMAGES };

Expand Down
12 changes: 12 additions & 0 deletions packages/wrangler/src/queues/subscription-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface EventDestination {
}

export enum EventSourceType {
ARTIFACTS = "artifacts",
ARTIFACTS_REPO = "artifacts.repo",
IMAGES = "images",
KV = "kv",
R2 = "r2",
Expand All @@ -28,6 +30,8 @@ export enum EventSourceType {
export const EVENT_SOURCE_TYPES = Object.values(EventSourceType);

export type EventSource =
| ArtifactsEventSource
| ArtifactsRepoEventSource
| ImagesEventSource
| KvEventSource
| R2EventSource
Expand All @@ -37,6 +41,14 @@ export type EventSource =
| WorkersBuildsWorkerEventSource
| WorkflowsWorkflowEventSource;

export interface ArtifactsEventSource {
type: EventSourceType.ARTIFACTS;
}

export interface ArtifactsRepoEventSource {
type: EventSourceType.ARTIFACTS_REPO;
}

export interface ImagesEventSource {
type: EventSourceType.IMAGES;
}
Expand Down
Loading