Cloudflare Workflow
Use Cloudflare Workflow when Cloudflare should run the durable work for your app. You still define the workflow in your app, and ViteHub forwards run creation and run lookup to Cloudflare Workflows.
Before you start
Deploy the app on Cloudflare Workers so the workflow binding exists at runtime.
Configure Cloudflare
export default defineNuxtConfig({
modules: ['@vitehub/workflow/nuxt'],
})
On Cloudflare hosting, ViteHub uses the Cloudflare workflow provider automatically.
Set workflow.binding only when you need a different binding name than the default, or when you want to pass an object that already has Cloudflare's create() and get() methods.
Define a workflow
Create a workflow file for the job you want to run.
export default defineWorkflow(async (input?: { title?: string }, context) => {
const title = input?.title?.trim() || 'Untitled draft'
return {
provider: context?.provider,
title,
}
})
Start a workflow run
import { runWorkflow } from '@vitehub/workflow'
export default defineEventHandler(async () => {
return await runWorkflow('publish-draft', {
title: 'Ship weekly digest',
})
})
If you call runWorkflow('publish-draft', payload), ViteHub forwards that payload to Cloudflare. When you do not provide your own params or payload start options, ViteHub writes the payload to Cloudflare's params field for you.
Cloudflare-specific options
| Option | Use it for |
|---|---|
workflow.binding | Override the default Cloudflare workflow binding name, or pass the binding object directly. |
What changes on Cloudflare
| Concern | Behavior |
|---|---|
| Binding lookup | getWorkflowRun(id) resolves the configured Cloudflare binding and calls binding.get(id). |
| Shared run methods | Every run supports id, status(), and stop(). |
| Cloudflare-only methods | Cloudflare runs also expose pause(), resume(), restart(), and sendEvent(event) under run.cloudflare. run.native gives you the raw Cloudflare workflow instance. |