i use websockets, durable objects, queues, d1, and cron jobs
i use websockets, durable objects, queues, d1, and cron jobs



--remote, no real operations are taking place on my buckets. So calling list doesn't return anything. --remote and call my worfklow, i get a workflow.not_found. --remote because workflows are not supported in remoteWORKFLOW.get(id) will return the finished instance? Also, does .restart() work for finished workflows too?

async tail(events, env, ctx) {
// Check if events array exists and has items
if (!Array.isArray(events) || events.length === 0) {
return new Response("No events found", { status: 200 });
}
// Only proceed if there's an exception AND exceptions array is not empty
const event = events[0];
if (event.outcome !== "exception" || !event.exceptions?.length) {
return new Response("No exception found", { status: 200 });
}
// Log the event structure to help us understand the data
console.log("Tail worker event:", JSON.stringify(events, null, 2));
... const payload = await step.do('prepares payload', async () => {
const isDev = this.env.ENVIRONMENT === 'dev';
const data = isDev ? mockData : event.payload;
console.log("Received payload:", JSON.stringify(data, null, 2));
throw new Error("Testing error handling with payload data");
return data;
});export class NeverGonnaWorkflow extends WorkflowEntrypoint<Env, NeverGonnaParams> {
async run(event: WorkflowEvent<NeverGonnaParams>, step: WorkflowStep) {
const { to, host, content } = event.payload;
await step.sleep('wait for the right moment', '135 seconds');
const callSid = await step.do('call person back', async () => {
const client = new Twilio(this.env.TWILIO_ACCOUNT_SID, this.env.TWILIO_AUTH_TOKEN);
// Say verb here does text to speech
// Play allows you to play media.
// The mp3 file is hosted on Cloudflare Workers using dynamic assets
const twiml = `
<Response>
<Say>Hello from a Cloudflare Workflow!</Say>
<Say>You said "${content}".</Say>
<Say>Check out this classic:</Say>
<Play>https://${host}/classic.mp3</Play>
</Response>`;
const call = await client.calls.create({
to,
from: this.env.TWILIO_PHONE_NUMBER,
twiml,
});
return call.sid;
});
return { success: true, callSid }; // <------ How to use this?
}
}const uploads = await Promise.all(
batch.map(async (image, index) => {
// Add 1 second sleep between uploads, but not before the first one
if (index > 0) {
await step.sleep(`delay-upload-${i}-${index}`, "1 second");
}
return step.do(
`process-image-${i}`,
{
retries: {
limit: 3,
delay: "5 seconds",
backoff: "exponential",
},
},
() => this.downloadAndUploadImage(image, orgId)
);
})
);