Skip to content

Commit

Permalink
fix: rename queue binding to match runtime (#455)
Browse files Browse the repository at this point in the history
Renames the queue binding in the miniflare plugin to "WorkerQueue" to
match the name in the Cloudflare runtime. This is small discrepancy is
particularly important for the workers-rs framework which validates the
types of bindings at runtime based on their constructor name, making it
impossible to use queues with miniflare.
  • Loading branch information
zebp authored Dec 12, 2022
1 parent 6efbf41 commit 7461ccc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions packages/queues/src/broker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ enum FlushType {

export const kSetFlushCallback = Symbol("kSetFlushCallback");

export class Queue<Body = unknown> implements QueueInterface<Body> {
export class WorkerQueue<Body = unknown> implements QueueInterface<Body> {
readonly #broker: QueueBroker;
readonly #queueName: string;
readonly #log?: Log;
Expand Down Expand Up @@ -263,23 +263,23 @@ export class Queue<Body = unknown> implements QueueInterface<Body> {
}

export class QueueBroker implements QueueBrokerInterface {
readonly #queues: Map<string, Queue>;
readonly #queues: Map<string, WorkerQueue>;
readonly #log?: Log;

constructor(log?: Log) {
this.#queues = new Map<string, Queue>();
this.#queues = new Map<string, WorkerQueue>();
this.#log = log;
}

getOrCreateQueue(name: string): Queue {
getOrCreateQueue(name: string): WorkerQueue {
let queue = this.#queues.get(name);
if (queue === undefined) {
this.#queues.set(name, (queue = new Queue(this, name, this.#log)));
this.#queues.set(name, (queue = new WorkerQueue(this, name, this.#log)));
}
return queue;
}

setConsumer(queue: Queue, consumer: Consumer) {
setConsumer(queue: WorkerQueue, consumer: Consumer) {
queue[kSetConsumer](consumer);
}
}
6 changes: 3 additions & 3 deletions packages/queues/test/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
DEFAULT_BATCH_SIZE,
DEFAULT_WAIT_MS,
Queue,
QueueBroker,
QueuesPlugin,
WorkerQueue,
} from "@miniflare/queues";
import {
Compatibility,
Expand Down Expand Up @@ -157,6 +157,6 @@ test("QueuesPlugin: setup: includes queues in bindings", async (t) => {
});

const result = await plugin.setup(factory);
t.true(result.bindings?.QUEUE1 instanceof Queue);
t.true(result.bindings?.QUEUE2 instanceof Queue);
t.true(result.bindings?.QUEUE1 instanceof WorkerQueue);
t.true(result.bindings?.QUEUE2 instanceof WorkerQueue);
});

0 comments on commit 7461ccc

Please sign in to comment.