Skip to content

# Execution engine

Chalk'it execution engine implements a synchronous/reactive scheduling algorithm.

DataNode instances are the nodes of a direct acyclic graph where edges are data dependencies. They each own a status describing their latest execution state. Last update time indicates the time of the last successful execution.

## DataNodes status

May have one of the following values :

- None : execution of the dataNode has not happened yet.
- Pending : execution of the dataNode is pending. This happens when a web-service call takes some time to complete.
- OK : last execution of the dataNode has completed sucessfully.
- Error : last execution has completed with error.

## Execution rules

- DataNode is executed if and only if all its predecessors completed their execution with an OK status.
- Every time a dataNode is succesfully computed (status "OK"), it triggers the execution of all its successors.
- Graph execution is interrupted at dataNodes with an Error status. Their successors are not executed.

## Scheduling instance

- At first start, graph is scheduled in a breadth-first order starting from source nodes. This is the first schedule instance.
- Some dataNodes might be updated through different ways : widget value written to dataNode, file imported into dataNode, formula modification, user refresh of dataNode, periodic behavior, chalkit scheduler API... Such update launches the execution of the corresponding dataNode and a new scheduling instance.

## Execution flow control parameters

The graph execution is controlled by the execution flow control parameters specified in dataNodes.

### Auto Start

When set to false, the associated dataNode is not executed on first execution of the dashboard nor in subsequent ones.

Otherwise, i.e. when set to true, default dataNodes execution behavior applies: all nodes are executed by the Chalk'it runtime when all their predecessors successfully completed.

For example, Auto Start can be set to false to avoid executing a heavy computation web-service at project load.

Default value is true.

### Sample Time

- When different from 0, the dataNode is executed every sample time. It's useful for ensuring a periodic real-time execution behavior.
- Every time a non null sample time is defined, the execution engine computes the greatest common divisor and use it as a its base timer.

Sample time is expressed in seconds and must be a multiple of 0.1s. Default value is 0.

### Explicit Trigger

- When set to true, the dataNode, in terms of execution flow control, is considered as a source node. It is no longer executed when a direct predecessor is updated. With this setting, it is only executed when it is explicitly triggered by an associated push button widget, by chalkit scheduler APIs, or by a click on the dataNode refresh icon present in the dataNodes list of tabs 1 or 3. Please refer to the Triggered POST example above.
- Otherwise (i.e. when set to false), default dataNodes execution behavior applies. Useful for implementing a form-like behavior (setting independently all required dataNode inputs, without executing it with each update, then explicitly triggering its execution).

Default value is false.

When a direct predecessor is updated, the dataNode, with an Explicit Trigger set to true and a previous succesfull computation (status "OK"), triggers the execution of all its successors.

### Execution flow control parameters : summary

The table below summarizes the execution flow control parameters for the currently available dataNode types in Chalk'it. The checkbox in the table indicates that the property can be customized by the user (true or false). Otherwise, they have the default value indicated above.

Type | Auto Start | Sample Time | Explicit Trigger
--- | --- | --- | ---
Variable |  |  |
Python Script |  |  |
JavaScript Script (client-side) |  |  |
REST web-service |  |  |
Generic text file reader |  |  |
Generic binary file reader |  |  |
CSV file reader |  |  |
CSV file player |  |  |
Unzip file |  |  |
Clock |  |  |
Delay |  |  |
Memory |  |  |
MQTT |  |  |
WebSocket receive |  |  |
WebSocket send |  |  |

Depending on the execution flow control parameters and the the data flow dependency, the dataNode execution is summarized in the following tables:

For nonperiodic dataNodes (Sample Time == 0)

Cases | Auto Start | Explicit Trigger | Run at project load | Run after predecessor update | Run after a user trigger*
--- | --- | --- | --- | --- | ---
1# | `False` | `False` | No | Yes | Yes
2# | `True` | `False` | Yes | Yes | Yes
3# | `False` | `True` | No | No | Yes
4# | `True` | `True` | Yes | No (last value) | Yes

*By an associated push button widget, by a click on the dataNode update icon , or by using executeDataNode API.

For periodic dataNodes (Sample Time > 0)

Cases | Auto Start | Explicit Trigger | Run at project load | Run after predecessor update | Run after a user trigger*
--- | --- | --- | --- | --- | ---
5# | `False` | `False` | No | Yes | Yes
6# | `True` | `False` | Yes | Yes | Yes
7# | `False` | `True` | No | No | Yes**
8# | `True` | `True` | Yes | No (last value) | Yes**

**For cases 7# and 8#, when the user explicitly triggers the periodic dataNode, the Explicit Trigger option is turned to `False`.

## DataNodes capabilities

In addition to execution flow control parameters, dataNodes may have common capabilites depending on their type.

### setInput with formula

Python or JavaScript code can be written to define input to dataNode computation.

### setValue from widget

Currently only Variable and Memory dataNodes have this property. It indicates that their workspace value can be modified by widgets that have write capabilities (such as sliders (horizontal slider ...), numeric input, editable table ...).

### setValue from file

The value of the dataNode can be assigned from a file. See example in Push button.

### setValue from script

Python or JavaScript code can be written to define input to Variable and Memory dataNodes, using chalkit API functions:

- setVariable
- setVariableProperty
- setVariables

This is useful to init and reset variables. See example reset-counter.xprjson.

The assessment of these functions is handled at the end of the current scheduling instance.

### DataNodes capabilities : summary

The table below summarizes currently available dataNodes in Chalk'it, as well as their major properties in terms of execution flow and data flow.

Type | setInput with formula | setValue from widget | setValue from file | setValue from script
--- | --- | --- | --- | ---
Variable |  |  |  |
Python Script |  |  |  |
JavaScript Script (client-side) |  |  |  |
REST web-service |  |  |  |
Generic text file reader |  |  |  |
Generic binary file reader |  |  |  |
CSV file reader |  |  |  |
CSV file player |  |  |  |
Unzip file |  |  |  |
Clock |  |  |  |
Delay |  |  |  |
Memory |  |  |  |
MQTT |  |  |  |
WebSocket receive |  |  |  |
WebSocket send |  |  |  |