workflow
Durable workflows for Webda: a flow is a sequence of operations with control flow, that survives restarts, retries its tasks, sleeps and runs each step as the user who launched it.
Install
pnpm add @webda/workflow
Usage
{
"services": {
"WorkflowService": {
"type": "Webda/WorkflowService"
}
}
}
useService<WorkflowService>("WorkflowService").registerFlow({
id: "Orders.Process",
version: "",
params: ["uuid"],
input: { type: "object", properties: { uuid: { type: "string" } } },
body: [
{
kind: "task",
id: "process/Orders.Capture",
operation: "Orders.Capture",
input: { obj: { uuid: { var: "uuid" } } },
options: { retries: 3 }
},
{ kind: "task", id: "process/Workflow.Sleep", operation: "Workflow.Sleep", input: { lit: { duration: "1d" } } },
{ kind: "task", id: "process/Orders.Remind", operation: "Orders.Remind", input: { obj: { uuid: { var: "uuid" } } } }
],
source: "code"
});
// The operation Orders.Process launches it and returns { uuid } of the WorkflowInstance
See the documentation for the graph format, the built-in operations, the task options and the engine parameters.
Operations run by a workflow should observe useAbortSignal() (aborted on timeout, lost lease and stop) to stop
early. An attempt that keeps running is ignored and the task may run again: operations are assumed to be idempotent.