Skip to content

Commit

Permalink
Implement Queues simulator as Durable Object
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbbot committed Aug 17, 2023
1 parent 9fe94f7 commit 16c49e4
Show file tree
Hide file tree
Showing 13 changed files with 732 additions and 672 deletions.
2 changes: 0 additions & 2 deletions packages/miniflare/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,6 @@ parameter in module format Workers.

#### Queues

> :warning: Queues are only supported with Node.js 18 or above.

- `queueProducers?: Record<string, string> | string[]`

Record mapping binding name to queue names to inject as `WorkerQueue` bindings
Expand Down
20 changes: 7 additions & 13 deletions packages/miniflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,14 @@ function getQueueConsumers(
}
}

// Populate all `deadLetterConsumer`s, note this may create cycles
for (const [queueName, consumer] of queueConsumers) {
if (consumer.deadLetterQueue !== undefined) {
// Check the dead letter queue isn't configured to be the queue itself
// (NOTE: Queues *does* permit DLQ cycles between multiple queues,
// i.e. if Q2 is DLQ for Q1, but Q1 is DLQ for Q2)
if (consumer.deadLetterQueue === queueName) {
throw new QueuesError(
"ERR_DEAD_LETTER_QUEUE_CYCLE",
`Dead letter queue for queue "${queueName}" cannot be itself`
);
}
consumer.deadLetterConsumer = queueConsumers.get(
consumer.deadLetterQueue
// Check the dead letter queue isn't configured to be the queue itself
// (NOTE: Queues *does* permit DLQ cycles between multiple queues,
// i.e. if Q2 is DLQ for Q1, but Q1 is DLQ for Q2)
if (consumer.deadLetterQueue === queueName) {
throw new QueuesError(
"ERR_DEAD_LETTER_QUEUE_CYCLE",
`Dead letter queue for queue "${queueName}" cannot be itself`
);
}
}
Expand Down
5 changes: 1 addition & 4 deletions packages/miniflare/src/plugins/queues/errors.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { HttpError, MiniflareError } from "../../shared";
import { MiniflareError } from "../../shared";

export type QueuesErrorCode =
| "ERR_V8_UNSUPPORTED" // V8 version too old
| "ERR_MULTIPLE_CONSUMERS" // Attempted to set multiple consumers for a single queue;
| "ERR_DEAD_LETTER_QUEUE_CYCLE"; // Attempted to set dead letter queue to self
export class QueuesError extends MiniflareError<QueuesErrorCode> {}

export class QueuesHTTPError extends HttpError {}
259 changes: 0 additions & 259 deletions packages/miniflare/src/plugins/queues/gateway.ts

This file was deleted.

Loading

0 comments on commit 16c49e4

Please sign in to comment.