All docs pages
Docs

Workflows

Multi-step processes that wait, retry and resume: onboarding, order fulfilment, approvals.

In stackly.json and the CLI it is workflows. Its use, live or draft, is counted as background runs; see Live app prices.

workflows · optional · needs backend, queues, objects · durable steps on Queues and Durable Objects

Multi-step processes that wait, retry and resume: onboarding sequences, order fulfilment, approvals, a reminder a day later.

Turn it on

"features": ["backend", "queues", "objects", "workflows"]

stackly features on workflows adds what it needs.

Use it

Define it in src/server/tasks.ts:

workflows: {
  onboarding: async (input: { userId: string }, step) => {
    const user = await step.do("load", () => loadUser(input.userId));
    await step.do("welcome", () => sendEmail({ to: user.email, subject: "Welcome", text: "…" }));
    await step.sleep("wait-a-day", 86_400);
    await step.do("tips", () => sendEmail({ to: user.email, subject: "Three tips", text: "…" }));
  },
},

Start it and check on it from any server code:

import { startWorkflow, workflowStatus } from "#/lib/workflows.server";

const { id } = await startWorkflow("onboarding", { userId }, { id: `onboarding:${userId}` }); // one per user
const status = await workflowStatus(id); // running | sleeping | done | failed, or null
  • Wrap every side effect in step.do("name", …): a retried or resumed run skips steps that finished. Step names are unique within a run.
  • A crash can land between doing a step and saving it, so write steps that are harmless twice.
  • Passing your own id starts that run once, even if the request is retried.

Limits

Input JSON at most 64 KB. step.sleep up to 30 days. Status is kept 30 days after the run.

Locally

stackly dev runs workflows on your machine, sleeps included.

All app features