Cloudflare Workflow

Configure Cloudflare Workflows and inspect runs from your app.

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

nuxt.config.ts
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.

server/workflows/publish-draft.ts
export default defineWorkflow(async (input?: { title?: string }, context) => {
  const title = input?.title?.trim() || 'Untitled draft'

  return {
    provider: context?.provider,
    title,
  }
})

Start a workflow run

server/api/workflows/publish.post.ts
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

OptionUse it for
workflow.bindingOverride the default Cloudflare workflow binding name, or pass the binding object directly.

What changes on Cloudflare

ConcernBehavior
Binding lookupgetWorkflowRun(id) resolves the configured Cloudflare binding and calls binding.get(id).
Shared run methodsEvery run supports id, status(), and stop().
Cloudflare-only methodsCloudflare runs also expose pause(), resume(), restart(), and sendEvent(event) under run.cloudflare. run.native gives you the raw Cloudflare workflow instance.
Choose Cloudflare when your app already depends on Workers and you want binding-based workflow orchestration in the same environment.