On the worker queue producer side, I

On the worker queue producer side, I have a tough time understanding why the worker sometimes just fails to complete the await env.QUEUE.send() ? From testing , I noticed "warmed up" invocations to the worker wouldn't have this issue but when it's idling after a while it would (for a good amount of time) just spins itself down before sending to the await env.QUEUE.send() call. request IDs affected: 930d4183797951e2 930d2b064f611f41 93118b1e9881e750 <-- happened again 9311fd876c65e673 <-- 7AM UTC 931525460cde4bc3 <-- 4PM UTC 9319b59e0fba7b28 <-- 6AM UTC (17/04) account ID: c0e0719247f81dc2f3d30844a8e0235c
1 Reply
Daniel
DanielOP5d ago
This is an example of the producer code:
export default {
async fetch(request, env, ctx): Promise<Response> {
console.log("Converting webhook request...");
const webhookRequest = await request.json() as unknown as WebhookRequest;
console.log("Processing webhook request...");
const dealId = [webhookRequest]
.filter(isWebhookRequest)
.filter(isValidWebhook)
.map(getDealId)[0];
const dealDetails = await getDetailAndAttachmentDataFromId(dealId, env);
const payload = await transformToPayload(dealDetails, env);
//send to queue
console.log("[5/5] Completed. Checking payload...");
if (!payload) {
console.log("No payload to send!");
return new Response(
JSON.stringify({
message: "Bad request",
}), {
status: 400,
});
}
try {
console.log("Sending to queue..."); // <-- last log to appear in worker logs
await env.QUEUE.send(payload); // <-- didn't send to queue
console.log(payload);
return new Response("Success", {
status: 200
});
} catch (err) {
console.error("Error sending to queue:", err);
return new Response(
JSON.stringify({
message: "Failed to send to queue",
error: (<any>err).message,
}), {
status: 500,
});
}
}
} satisfies ExportedHandler<Env>;
export default {
async fetch(request, env, ctx): Promise<Response> {
console.log("Converting webhook request...");
const webhookRequest = await request.json() as unknown as WebhookRequest;
console.log("Processing webhook request...");
const dealId = [webhookRequest]
.filter(isWebhookRequest)
.filter(isValidWebhook)
.map(getDealId)[0];
const dealDetails = await getDetailAndAttachmentDataFromId(dealId, env);
const payload = await transformToPayload(dealDetails, env);
//send to queue
console.log("[5/5] Completed. Checking payload...");
if (!payload) {
console.log("No payload to send!");
return new Response(
JSON.stringify({
message: "Bad request",
}), {
status: 400,
});
}
try {
console.log("Sending to queue..."); // <-- last log to appear in worker logs
await env.QUEUE.send(payload); // <-- didn't send to queue
console.log(payload);
return new Response("Success", {
status: 200
});
} catch (err) {
console.error("Error sending to queue:", err);
return new Response(
JSON.stringify({
message: "Failed to send to queue",
error: (<any>err).message,
}), {
status: 500,
});
}
}
} satisfies ExportedHandler<Env>;

Did you find this page helpful?