Skip to content

Commit b563282

Browse files
committed
fix code block
1 parent 6af7719 commit b563282

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

src/content/docs/workers/testing/miniflare/get-started.mdx

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -103,46 +103,46 @@ to workers respectively:
103103
import { Miniflare } from "miniflare";
104104

105105
const mf = new Miniflare({
106+
modules: true,
106107
script: `
107-
export default {
108-
let lastScheduledController;
109-
let lastQueueBatch;
110-
async fetch(request, env, ctx) {
111-
const { pathname } = new URL(request.url);
112-
if (pathname === "/scheduled") {
113-
return Response.json({
114-
scheduledTime: lastScheduledController?.scheduledTime,
115-
cron: lastScheduledController?.cron,
116-
});
117-
} else if (pathname === "/queue") {
118-
return Response.json({
119-
queue: lastQueueBatch.queue,
120-
messages: lastQueueBatch.messages.map((message) => ({
121-
id: message.id,
122-
timestamp: message.timestamp.getTime(),
123-
body: message.body,
124-
bodyType: message.body.constructor.name,
125-
})),
126-
});
127-
} else if (pathname === "/get-url") {
128-
return new Response(request.url);
129-
} else {
130-
return new Response(null, { status: 404 });
131-
}
132-
},
133-
async scheduled(controller, env, ctx) {
134-
lastScheduledController = controller;
135-
if (controller.cron === "* * * * *") controller.noRetry();
136-
},
137-
async queue(batch, env, ctx) {
138-
lastQueueBatch = batch;
139-
if (batch.queue === "needy") batch.retryAll();
140-
for (const message of batch.messages) {
141-
if (message.id === "perfect") message.ack();
142-
}
143-
}
144-
}
145-
`,
108+
let lastScheduledController;
109+
let lastQueueBatch;
110+
export default {
111+
async fetch(request, env, ctx) {
112+
const { pathname } = new URL(request.url);
113+
if (pathname === "/scheduled") {
114+
return Response.json({
115+
scheduledTime: lastScheduledController?.scheduledTime,
116+
cron: lastScheduledController?.cron,
117+
});
118+
} else if (pathname === "/queue") {
119+
return Response.json({
120+
queue: lastQueueBatch.queue,
121+
messages: lastQueueBatch.messages.map((message) => ({
122+
id: message.id,
123+
timestamp: message.timestamp.getTime(),
124+
body: message.body,
125+
bodyType: message.body.constructor.name,
126+
})),
127+
});
128+
} else if (pathname === "/get-url") {
129+
return new Response(request.url);
130+
} else {
131+
return new Response(null, { status: 404 });
132+
}
133+
},
134+
async scheduled(controller, env, ctx) {
135+
lastScheduledController = controller;
136+
if (controller.cron === "* * * * *") controller.noRetry();
137+
},
138+
async queue(batch, env, ctx) {
139+
lastQueueBatch = batch;
140+
if (batch.queue === "needy") batch.retryAll();
141+
for (const message of batch.messages) {
142+
if (message.id === "perfect") message.ack();
143+
}
144+
}
145+
}`,
146146
});
147147

148148
const res = await mf.dispatchFetch("http://localhost:8787/", {
@@ -158,8 +158,8 @@ const scheduledResult = await worker.scheduled({
158158
console.log(scheduledResult); // { outcome: "ok", noRetry: true });
159159

160160
const queueResult = await worker.queue("needy", [
161-
{ id: "a", timestamp: new Date(1000), body: "a" },
162-
{ id: "b", timestamp: new Date(2000), body: { b: 1 } },
161+
{ id: "a", timestamp: new Date(1000), body: "a", attempts: 1 },
162+
{ id: "b", timestamp: new Date(2000), body: { b: 1 }, attempts: 1 },
163163
]);
164164
console.log(queueResult); // { outcome: "ok", retryAll: true, ackAll: false, explicitRetries: [], explicitAcks: []}
165165
```

0 commit comments

Comments
 (0)