Skip to main content

11. Events and schedules

Triggers

TriggerMechanism
An application decidesPOST /api/workflow/{name}
A person decidesThe UI, which calls the same endpoint
A message arrivesAn event handler
A time is reachedA schedule
Another run asksSTART_WORKFLOW or SUB_WORKFLOW task

This page covers the third and fourth.

Event handlers

An event handler is a stored rule with four parts:

PartMeaning
sourceWhere messages come from: eventgrid:{topic}, servicebus:{topic}/{subscription}, or eventhub:{hub}
conditionA JSONPath predicate on the message body, for example $.status == 'READY'. Empty means always.
actionsWhat to do: start_workflow, complete_task, fail_task, terminate_workflow
activeOn or off. Default off.

Example, registered through POST /api/event:

{ "name": "start_fulfilment_on_order_ready",
"source": "eventgrid:orders",
"condition": "$.status == 'READY'",
"actions": [ { "action": "start_workflow",
"start_workflow": { "name": "fulfil_order", "version": 1,
"correlationId": "${orderId}",
"input": { "orderId": "${orderId}" } } } ],
"active": true }

${...} in actions refers to fields of the message body.

Sources

Event Grid, Service Bus topics, and Event Hubs each deliver to a trigger in the engine. All three call the same handler function, which loads the active handlers for the source, evaluates each condition, and runs the matching actions. Every attempt writes an event_execution row: handler, message id, action, result. GET /api/event/executions reads them.

SourceUse when
Event GridDiscrete events. Also carries events the engine publishes itself with PUBLISH_EVENT.
Service Bus topicMessages must be processed in order.
Event HubsHigh-volume streams from the data platform, evaluated in batches.

Status events

When a definition sets statusListenerEnabled: true, the engine publishes WorkflowStatusChanged and TaskStatusChanged to the Event Grid topic wos-status on every change. Consumers subscribe with a filter on workflow name. Typical consumers: a Teams notifier, a CRM mirror, the analytics platform.

Run-to-run messaging

A run publishes with PUBLISH_EVENT. A handler on the same topic starts or continues another run. Neither run knows the other's id. The correlationId field links them for search.

Schedules

A schedule is a row: {name, workflowName, workflowVersion, cron, input, active}, registered through POST /api/schedule. A timer function runs every minute, finds active schedules whose cron matches, and starts each with the stored input and correlation id {schedule name}:{timestamp}. Each schedule starts at most one run per minute.