From cf-saas-stack
Cloudflare Workflows patterns for background tasks and async processing
How this skill is triggered — by the user, by Claude, or both
Slash command
/cf-saas-stack:cloudflare-workflowsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Use Cloudflare Workflows for background tasks instead of running them in request handlers.
Use Cloudflare Workflows for background tasks instead of running them in request handlers.
// workflows/my-task.ts
import { WorkflowEntrypoint, type WorkflowEvent, type WorkflowStep, env } from "cloudflare:workers";
import { getDb } from "@/db";
export interface MyTaskWorkflowPayload {
resourceId: string;
userId: string;
}
export class MyTaskWorkflow extends WorkflowEntrypoint<Env, MyTaskWorkflowPayload> {
async run(event: WorkflowEvent<MyTaskWorkflowPayload>, step: WorkflowStep) {
const { resourceId, userId } = event.payload;
// Step 1: Do work (each step is retried on failure)
const result = await step.do("process-data", async () => {
return { processed: true };
});
// Step 2: Update database
await step.do("save-result", async () => {
const db = await getDb(this.env.DATABASE);
// Update record...
});
return { success: true };
}
}
{ "binding": "MY_TASK_WORKFLOW", "name": "landfall-my-task-workflow", "class_name": "MyTaskWorkflow" }
export { MyTaskWorkflow } from "../workflows/my-task";
workflows: {
MyTaskWorkflow: opts.cfContext.MY_TASK_WORKFLOW,
}
bun run typegentry {
await ctx.workflows.MyTaskWorkflow.create({
params: { resourceId, userId: ctx.auth.user.id },
});
} catch (error) {
log.error({ err: error }, "Failed to start workflow");
// Don't fail the request if workflow fails to start
}
step.do() may retry - ensure operations are safe to repeatnpx claudepluginhub casper-studios/casper-marketplace --plugin cf-saas-stackBuilds and debugs Cloudflare Workflows for durable, long-running execution with multi-step workflows, retries, state persistence, and event handling.
Builds reliable background jobs, AI workflows, and scheduled tasks using Trigger.dev's TypeScript-first platform with durable execution and built-in integrations.
Expert guidance on Trigger.dev for building background jobs, AI workflows, and reliable async execution with TypeScript-first design. Covers tasks, integrations, scheduling, and deployment.