# Workflows

> Engine-neutral workflow runs that members read through RLS, with a Realtime ping per status change and workflow_run.completed, .failed and .cancelled outbox events; cron schedules with idempotent fires, counting semaphores, admission control for starts (concurrency, debounce, singleton) and a retention purge.

- Category: Automation
- Module: `workflows`
- Modes: `managed`, `custom`
- Docs: https://bettersupabase.com/docs/blocks/workflows
- Page: https://bettersupabase.com/blocks/workflows

## Install

```bash
npx better-supabase add workflows
```

The command also installs `updated-at`, `memberships`, `permissions`.

## Configure

Add the block to `better-supabase.config.ts`:

```ts
import { defineConfig } from "better-supabase/config";

export default defineConfig({
  blocks: {
    // Required by workflows; add installs them too.
    "updated-at": {},
    memberships: {},
    permissions: {},
    // Modes: "managed", "custom". The default is "managed".
    workflows: { mode: "managed" },
  },
});
```

## Client

The React hooks are the registry item `@better-supabase/use-workflows` (`npx shadcn add @better-supabase/use-workflows`). They return data and actions and render no UI. Source: https://github.com/ScaleDockHQ/better-supabase/blob/main/packages/registry/items/hooks/use-workflows.ts

## Events

- `workflow_run.cancelled`
- `workflow_run.completed`
- `workflow_run.failed`

## Related blocks

Requires: [memberships](https://bettersupabase.com/blocks/memberships.md), [permissions](https://bettersupabase.com/blocks/permissions.md)

Works with: [data-lifecycle](https://bettersupabase.com/blocks/data-lifecycle.md)

## Recipes

- [Workflow canvas](https://bettersupabase.com/recipes/workflow-canvas.md): A node editor for a workflow definition that saves drafts, publishes versions and runs the workflow.
- [Workflow runs](https://bettersupabase.com/recipes/workflow-runs.md): The latest workflow runs with their status, which update while a run is in progress.
