Skip to content

Commit 0a5b965

Browse files
committed
- Documented the difference between an event-driven schedule and a startup listen task
- Added examples to document event-driven and cron schedules Signed-off-by: Charles d'Avernas <charles.davernas@neuroglia.io>
1 parent feb9ca9 commit 0a5b965

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

dsl.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ Workflow scheduling in ServerlessWorkflow allows developers to specify when and
150150

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

153+
##### Distinguishing event-driven Scheduling from start `listen` Tasks
154+
155+
While both `schedule.on` and a start listener task enable event-driven execution of workflows, they serve distinct purposes and have different implications:
156+
157+
- **`schedule.on`**: This property defines when a new instance of a workflow should be created based on an external event. When an event occurs that matches the criteria specified in `schedule.on`, a new workflow instance is initiated. The key point here is that `schedule.on` solely manages the creation of new workflow instances. Any faults or timeouts related to the scheduling process itself are typically invisible to the user and do not impact the workflow instance.
158+
159+
- **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 lies in the fact that a start listener task operates within the context of 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.
160+
161+
In essence, 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 important 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 have a direct and potentially severe impact on the workflow instance they belong to.
162+
153163
### Task Flow
154164

155165
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)