Skip to content

Commit b4d0ace

Browse files
committed
[docs] Add state machine callback documentation
1 parent 59aab4f commit b4d0ace

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

docs/handbook/overview.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,35 @@ This is the order of callback execution upon a state transition:
5353
5. `enter_<NEW_STATE>`, `<NEW_STATE>` - called after entering `<NEW_STATE>`
5454
6. `enter_state` - called after entering all states
5555
7. `after_<EVENT>`, `<EVENT>` - called after event named `<EVENT>`
56-
8. `after_event` - called after all events
56+
8. `after_event` - called after all events
57+
58+
Callback execution is further refined with integer indexes, with the syntax `±index`, e.g. `before_CONFIGURE+2`, `enter_CONFIGURED-666`. An expression with no index is assumed to be indexed `+0`. These indexes do not correspond to timestamps, they are discrete labels that allow more granularity in callbacks, ensuring a strict ordering of callback opportunities within a given callback moment. Thus, `before_CONFIGURE+2` will complete execution strictly after `before_CONFIGURE` runs, but strictly before `enter_CONFIGURED-666` is executed.
59+
60+
## Workflow hook calls
61+
62+
The state machine callback moments are exposed to the AliECS workflow template interface and can be used as triggers or synchronization points for integration plugin function calls. The `call` block can be used for this purpose, with similar syntax to the `task` block used for controllable tasks. Its fields are as follows.
63+
* `func` - mandatory, it parses as an `antonmedv/expr` expression that corresponds to a call to a function that belongs to an integration plugin object (e.g. `bookkeeping.StartOfRun()`, `dcs.EndOfRun()`, etc.).
64+
* `trigger` - mandatory, the expression at `func` will be executed once the state machine reaches this moment.
65+
* `await` - optional, if absent it defaults to the same as `trigger`, the expression at `func` needs to finish by this moment, and the state machine will block until `func` completes.
66+
* `timeout` - optional, Go `time.Duration` expression, the maximum time `func` will be granted to complete before its context is invalidated.
67+
* `critical` - optional, it defaults to `true`, if `true` then a failure or timeout for `func` will send the environment state machine to `ERROR`.
68+
69+
Consider the following example:
70+
```
71+
# Trigger and await are different: any number of other operations may happen concurrently in between. Regardless of when in time the call actually finishes, its result isn't collected until the environment state machine reaches `after_RESET+0`. The state machine will only block if it reaches `after_RESET+0` and the call isn't done yet (completed or timed out).
72+
- name: reset
73+
call:
74+
func: odc.Reset()
75+
trigger: before_RESET
76+
await: after_RESET
77+
timeout: "{{ odc_reset_timeout }}"
78+
critical: true
79+
# Trigger and await are the same (the await expression could be omitted here): the call must begin and end within the `after_RESET+100` step. If the workflow template defines no other calls straddling `after_RESET+100` then this call is fully serialized with respect to the state machine and its execution blocks everything else.
80+
- name: part-term
81+
call:
82+
func: odc.PartitionTerminate()
83+
trigger: after_RESET+100
84+
await: after_RESET+100
85+
timeout: "{{ odc_partitionterminate_timeout }}"
86+
critical: true
87+
```

0 commit comments

Comments
 (0)