How to define a workflow
Start with a YAML file containing a document section and a do list.
To run the examples, complete the SQLite setup and keep its worker running. Run the commands from a second terminal in the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline. Save each definition under the file name used in its definition post command.
Save this first definition as hello.yaml:
The worker logs Workflow completed with output with {"message":"Order received"}.
Identify the workflow
The document section contains four required fields:
Field | Purpose |
|---|---|
| Open Workflow DSL version, such as |
| Namespace the runner serves |
| Workflow name within that namespace |
| Semantic version of this workflow definition |
The combination of namespace, name and version identifies a definition. Use the optional title and summary fields for human-readable descriptions.
Define and connect tasks
Write one named task per entry in do. Tasks run in list order by default. Add then to jump to a named task or end execution. A switch lists named cases with conditions and flow directives. A final case without when provides a fallback.
Validate and transform data
Use input.schema.document to declare a JSON Schema and output.as to shape the final result. Expressions delimited by ${ ... } use jq. The task input is . and the original workflow input is available as $workflow.input.
Save it as validate-and-route-order.yaml, register it and start one small order, one large order and one order without a total:
The first instance completes with {"orderId":"ORD-301","status":"accepted"} and the second with {"orderId":"ORD-302","status":"needs-review"}. The third is refused before any instance exists: the CLI prints Input validation failed against workflow schema and Missing required field(s): 'total'.
Reuse workflow resources
Use the use section for named functions, errors, authentication policies and retry policies. The following workflow declares a reusable retry policy and selects it in catch.retry.
The request goes to the tutorial shop. Its fail and failTimes query parameters make the shop answer HTTP 503 a chosen number of times, and key counts those failures per instance. Start the shop from the root of the Lemline source checkout, then save the definition as retry-and-fallback.yaml and run it with no failure, one failure and five failures:
The first two instances return the stock, {"sku":"SKU-1","available":100,"reserved":0}; the second one after a retry about 2 seconds later. The third fails four times (the call and three retries), then returns {"inventory":[],"stale":true} after the catch block runs. The worker picks up delayed retries every 10 seconds, so allow about a minute. The shop page lists every attempt under Requests. Stop the shop when you are done:
See Publish and Run a Workflow to register and start your definition, or DSL Syntax Reference for the main workflow sections and task types.