How to publish and run a workflow
This guide covers publishing a workflow definition to Lemline and starting instances of it, with the CLI or with the gRPC gateway.
Prerequisites
Complete the SQLite setup and keep its worker running. Run the commands below from a second terminal in the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline. The production section lists what changes with a shared database and broker.
Understanding the Workflow Lifecycle
Define: write a workflow definition in YAML
Publish: store the definition in Lemline's database
Start: create instances of the workflow
Observe: follow instances in the dashboard, through the gateway or in the worker log
Publishing a Workflow Definition
Save this definition, the conditional greeting from Acknowledge the first order, as acknowledge-order.yaml:
The CLI answers Workflow successfully created: 'acknowledge-order' (version '0.1.3'). The namespace, name and version come from the document section of the file. Lemline rejects a file that is not a readable definition. Nothing is stored for a rejected file, and the command exits with a non-zero code.
Publishing Multiple Workflows
Pass a directory to publish every definition file it contains. Add --recursive to include subdirectories.
Each file is reported on its own line. Here the only definition is already registered, so the CLI prints Workflow already exists (use --force to overwrite) and still exits successfully.
Republishing a Workflow
A definition with the same namespace, name and version is not replaced unless you add --force:
The CLI answers Workflow successfully updated.
Checking Published Definitions
The CLI lists the namespace, name and version of each definition, here tutorial acknowledge-order 0.1.3, then prints the selected definition. With several definitions it asks which one to show. In a script, pass the namespace, name and version instead, as in bin/lemline definition get tutorial acknowledge-order 0.1.3.
Running a Workflow Instance
Using the CLI
The command takes a namespace, a name and an optional version:
Without a version, the latest published version is started. Provide input as JSON:
The command prints Instance <id> started successfully with the version it chose, here 0.1.3, and returns; it does not wait for the workflow to finish. The running worker executes the instance and logs Workflow completed with output with {"message":"Good morning: order received for ORD-101!"}.
Using the gRPC Gateway
Programs start instances through the gateway's StartInstance RPC (lemline.gateway.v1.GatewayService). Follow the gateway tutorial for a complete request and a way to read the resulting output.
Retry a gateway start safely
Before the first call, generate and save a UUIDv7 as
instance_idfor the logical request. Set an explicit workflow version so a deployment between attempts cannot change which version the request resolves to.If the response is lost or the request times out, repeat the same request with the same ID, namespace, name, version, input and time zone.
Treat
START_INSTANCE_RESULT_ACCEPTED_NEWandSTART_INSTANCE_RESULT_ACCEPTED_EXISTINGas acceptance of the same instance. If you receiveALREADY_EXISTS, compare the original parameters with the retry. Reusing an ID with different effective parameters is a conflict.
Use the returned ID to follow the instance events. See Start Idempotency for the comparison rules.
Checking Instance Status
The CLI has no command to read instances. Use:
the gateway RPCs
GetInstance,ListInstancesandListInstanceEventsthe worker log (
bin/lemline listen --debuglogs each workflow output)on the SQLite setup, the
lemline_lifecycle_eventstable ofanalytics.db
Running Workflows in Production
1. Use a Production Database
Pass the password as LEMLINE_DATABASE_POSTGRESQL_PASSWORD.
2. Configure a Message Broker
3. Run Several Runners
Start several lemline listen processes with the same database and broker. They share the work; no load balancer is needed.
4. Check Health
The worker serves health and metrics on port 8080, or on the port given with --metrics-port:
A healthy worker answers "status": "UP".
5. Monitor Activity
6. Keep One Configuration per Environment
Troubleshooting
Workflow Won't Publish
Invalid definition: check the error printed by
definition post.Database connectivity: ensure the database is reachable.
Version already exists: use
--forceto replace it, or publish a new version.
Workflow Instance Won't Start
Unknown workflow: check namespace, name and version with
bin/lemline definition get.Invalid input: input must be valid JSON and match the workflow's input schema.
Instance Does Not Progress
No runner: check that a runner is running and serves the workflow's namespace (
lemline.namespaces).External dependencies: check the services the workflow calls.
Waits: the workflow may be waiting for a timer or an event.
Next Steps
Learn how to monitor workflow execution
Understand how to debug faults in task execution