Netlify Workflow

Configure Netlify Async Workloads and run discovered workflows on Netlify.

Use Netlify Workflow when durable work should run on Netlify Async Workloads while you keep the same ViteHub workflow files and runWorkflow() calls.

Before you start

Terminal
pnpm add https://pkg.pr.new/vite-hub/vitehub/@vitehub/workflow@main @netlify/async-workloads

Configure Netlify

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@vitehub/workflow/nuxt'],
})

On Netlify hosting, ViteHub uses the Netlify workflow provider automatically.

Add workflow.baseUrl or workflow.apiKey only when you need to publish workflow events outside Netlify's normal runtime context.

Define a workflow

server/workflows/publish-draft.ts
import { defineWorkflow } from '@vitehub/workflow'

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

  await context?.step?.run('persist-title', async () => title)
  await context?.step?.sleep('wait-before-publish', '30 seconds')

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

On Netlify, context.step.run() and context.step.sleep() map to Async Workloads step APIs, and context.sendEvent() uses Netlify's event publishing client.

Start a workflow run

server/api/workflows/publish.post.ts
import { runWorkflow } from '@vitehub/workflow'

export default defineEventHandler(async () => {
  const run = await runWorkflow('publish-draft', {
    title: 'Ship weekly digest',
  })

  return {
    eventId: run.id,
    status: await run.status(),
  }
})

runWorkflow() returns a handle with the Netlify event id. Netlify does not currently let ViteHub reconnect to a running workload later by id.

Netlify-specific options

OptionUse it for
workflow.baseUrlPoint ViteHub at a custom Netlify Async Workloads base URL.
workflow.apiKeyAuthenticate Async Workloads requests outside Netlify's default runtime context.

Netlify limitations

ConcernBehavior
Run lookupgetWorkflowRun(id) returns null because Netlify Async Workloads does not expose a public way to fetch an existing run by id yet.
Run cancellationrun.stop() is not supported.
Definition timeouttimeout stays in the portable API but Netlify ignores it in this release.
Event namingDiscovered workflow names map 1:1 to Async Workloads event names.
Choose Netlify when you want step-based retries and sleeps on Netlify, but still want ViteHub to keep the same workflow files and runWorkflow() API.