Workflows

Depends: backend

Add background workflows to a project created before they were part of every new one.

Syntax

$ vela enable workflows

Projects created with Vela 0.13 or later already have everything this adds, and running it there changes nothing. On an older project it brings the same files in:

  • src/lib/server/workflows.ts - The OpenWorkflow client, the superuser client for steps, and the worker
  • src/lib/workflows/ - Where workflow files go, with a README
  • An init hook in src/hooks.server.ts that starts the worker when the server does

and installs openworkflow, openworkflow-pocketbase and croner.

The init hook

The hook is appended to src/hooks.server.ts as it is, whether the file exports a bare handlePocketbase or a sequence of handles:

import type { ServerInit } from '@sveltejs/kit';
import { startWorker } from '$lib/server/workflows';

export const init: ServerInit = () => startWorker();

A file that already exports an init is left alone, with a note to call startWorker() from it yourself.

After enabling, vela generate workflow adds the first workflow.