Skip to content

Commit eb050fd

Browse files
Merge pull request serverlessworkflow#987 from neuroglia-io/fix-schedule-on-documentation
Document the difference between an event-driven schedule and a startup listen task
2 parents 9e4f3a0 + de12562 commit eb050fd

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

dsl.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [Components](#components)
1313
+ [Task](#task)
1414
- [Scheduling](#scheduling)
15+
+ [Event-Driven Scheduling](#event-driven-scheduling)
1516
+ [Task Flow](#task-flow)
1617
+ [Data Flow](#data-flow)
1718
+ [Runtime Expressions](#runtime-expressions)
@@ -150,6 +151,24 @@ Workflow scheduling in ServerlessWorkflow allows developers to specify when and
150151

151152
See the [DSL reference](dsl-reference.md#schedule) for more details about workflow scheduling.
152153

154+
##### Event-driven scheduling
155+
156+
###### Input of event-driven scheduled workflows
157+
158+
In event-driven scheduled workflows, the input is structured as an array containing the events that trigger the execution of the workflow. This array serves as a vital resource, providing workflow authors access to all relevant data associated with each triggering event. When an event activates the workflow, it populates this array with one or more occurrences, allowing authors to process multiple events simultaneously as needed.
159+
160+
Authors can reference individual events within the array using syntax such as $workflow.input[index], where index indicates the event's position, starting from 0. For instance, $workflow.input[0] refers to the first event, while $workflow.input[1] refers to the second. This structure allows for easy access to specific event details, and if multiple events are received at once, authors can iterate through the array to handle each one appropriately. This flexibility ensures that workflows can respond effectively to various conditions and triggers, enhancing their overall responsiveness and functionality.
161+
162+
###### Distinguishing event-driven scheduling from start `listen` Tasks
163+
164+
While both `schedule.on` and a start listener task enable event-driven execution of workflows, they serve distinct purposes and have different implications:
165+
166+
- **`schedule.on`**: This property defines when a new workflow instance should be created based on an external event. When an event matches the criteria specified in `schedule.on`, a new workflow instance is initiated. The critical point here is that `schedule.on` solely manages the creation of new workflow instances. Any faults or timeouts related to the scheduling process are typically invisible to the user and do not impact the workflow instance.
167+
168+
- **Start `listen` task**: A start listener task defines a task that must be undertaken after a new workflow instance has been created. This task listens for specific events and begins processing once the instance is active. The critical difference is that a start listener task operates within an already instantiated workflow. If a start listener task experiences a timeout or fault, it can cause the entire workflow instance to fail or behave unexpectedly, directly impacting the flow's execution and outcome.
169+
170+
While `schedule.on` is concerned with *when* a new workflow instance should be initiated, a start listener task deals with *what* should happen once the instance is active. This distinction is crucial because it influences how errors and timeouts are handled—`schedule.on` faults are typically invisible and do not affect the workflow, whereas start listener task failures can directly and potentially severely impact the workflow instance they belong to.
171+
153172
### Task Flow
154173

155174
A workflow begins with the first task defined.

examples/cron-schedule.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
document:
2+
dsl: 1.0.0-alpha1
3+
namespace: examples
4+
name: cron-schedule
5+
version: 1.0.0-alpha1
6+
schedule:
7+
cron: 0 0 * * *
8+
do:
9+
- backup:
10+
call: http
11+
with:
12+
method: post
13+
endpoint: https://example.com/api/v1/backup/start

examples/event-driven-schedule.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
document:
2+
dsl: 1.0.0-alpha1
3+
namespace: examples
4+
name: event-driven-schedule
5+
version: 1.0.0-alpha1
6+
schedule:
7+
on:
8+
one:
9+
with:
10+
type: com.example.hospital.events.patients.heartbeat.low
11+
do:
12+
- callNurse:
13+
call: http
14+
with:
15+
method: post
16+
endpoint: https://hospital.example.com/api/v1/notify
17+
body:
18+
patientId: ${ $workflow.input[0].data.patient.id }
19+
patientName: ${ $workflow.input[0].data.patient.name }
20+
roomNumber: ${ $workflow.input[0].data.patient.room.number }
21+
vitals:
22+
heartRate: ${ $workflow.input[0].data.patient.vitals.bpm }
23+
timestamp: ${ $workflow.input[0].data.timestamp }
24+
message: "Alert: Patient's heartbeat is critically low. Immediate attention required."

0 commit comments

Comments
 (0)