Table of Contents
Automatic Execution of Activities
Activities of a DCR model can execute automatically when:
- They have a “robot” role, or
- They are specified as a continuation for an effect.
Use robot roles to automatically execute computations or effects as a reponse to users executing activities. Use effect continuations to collect output data from effects, and to react to failures.
If in doubt, you probably want a robot.
Robots
Robots are activities with special roles. Those activites are run automatically. You use them to automatically perform follow-up activities, like computing values or executing effects.
Execution Cycles
The DCR runtime runs robots as part of an execution cycle. An execution cycle is started whenever the host system requests the DCR runtime to execute an activity, or when the runtime wakes up after a delay has expired.
Each execution cycle follows this fixed sequence:
- Prime robots run first (if enabled)
- User activity executes (the activity requested by the host system)
- Regular robots run (Robot and LocalRobot, as long as eligible robots remain)
- Terminator robots run last (if enabled)
This entire cycle completes as part of processing a single request from the host system. Prime and Terminator robots are not global one-time activities—they run at the beginning and end of every execution cycle.
You make an activity a robot by assigning one of the following roles to it. The most common is simply "Robot", which causes the activity to be automatically run whenever it is pending.
| Role | When in cycle? | On what conditions? | How many times per cycle? |
|---|---|---|---|
Robot:Prime |
First: before the user activity executes | Runs only if enabled | At most once |
Robot |
Middle: after the user activity, before LocalRobot |
Runs only if enabled and pending | Any number |
LocalRobot |
Middle: after the user activity and Robot |
Runs only if enabled and locally pending | Any number |
Robot:Terminator |
Last: after the user activity and all other robots | Runs only if enabled | At most once |
Robots can toggle each other on and off: If a Robot A makes another Robot B enabled and pending, then B will subsequently be considered for execution within the same cycle.
Robots are also executed during model initialisation, following the same cycle sequence and subject to the same ordering and limits.
Effect Continuations
Any effect will either complete successfully, time out, or fail. To react to the conclusion of an effect, the DCR model can specify an activity to execute automatically in any or all of these three cases:
| Parameter | Continuation value | Triggered when… |
|---|---|---|
ContinueOnOk |
ok |
The effect completes successfully |
ContinueOnFail |
fail |
The effect fails |
ContinueOnTimeout |
timeout |
The effect times out |
In DCR v1.2 semantics, continuations are guaranteed to run immediately after the activity carrying the effect. However, this invariant is subject to change in future revision of the DCR semantics; if possible, design your models to be tolerant to continuations happening possibly only /after/ other activities, including robots.
When an effect continuation executes, the corresponding activity may itself have effects or robot roles. In such cases, the normal automatic execution rules apply — that is, the continuation activity may trigger additional effects, which in turn may have continuations or enable further robots.
Consider using the reserved role System for continuation effects; see below.
Visibility of Automatic Activities
Automatic activities are typically irrelevant to end-users; /should not/ be shown in default user-interfaces. For this reason, DCR recommends that host systems, such as KMD WorkZone, hides activities with the following roles from users:
Robot:PrimeRobotLocalRobotRobot:TerminatorSystem
However, for trouble-shooting, it can be helpful to have special views that do show robots, both in lists
of currently enabled activities and in logs.
Limits on Automatic Execution
Automatic execution may cause /more/ automatic execution: Robots may cause other robots to run; as may effects continuations. And effect continuations could themselves cause more effects to execute, in turn incurring more effect continuations etc. To ensure termination and prevent excessive background work, the DCR runtime imposes strict limits on both duration and count of automatic events.
All automatic execution happens within an execution cycle (see above). Each execution cycle processes a single request from the host system—either to execute a specific activity or in response to a wakeup after a delay.
-
At most 256 robots are executed during an execution cycle. This limit is configurable via the
MaxRobotsoption. The limit cannot be removed, but it can be increased. It is common to increase this to 4096 or even further, if your graphs are doing batch-like processing. -
Optionally, you can set the
Timeoutoption, which limits the total wall-clock time spent executing one execution cycle. -
At most 64 /consecutive/ effect continuations are ever executed. This limit is not configurable and cannot be turned off.
Between them, these limits ensure that executing an activity in a DCR graph always terminates. It is not possible to construct a DCR graph which repeats automatic execution infinitely.
The limits are in place exclusively to protect production systems. Your graphs should never reach these limits, and there is no mechanism for the DCR graph itself to determine that it has met a limit. Set limits appropriately.
Configuration
The following table summarises the configuration options pertaining to automatic execution.
| Configuration Key | Type | Default | Description |
|---|---|---|---|
WithRobots |
bool |
true |
Determines whether activities with robot roles are run automatically within an execution cycle. When false, no robots will execute (equivalent to MaxRobots: 0). |
MaxRobots |
int |
256 |
Maximum number of robot activities to execute during one execution cycle. Setting this to 0 is equivalent to WithRobots: false. This limit cannot be removed, but can be increased (e.g., to 4096 or higher for batch-like processing). |
Timeout |
TimeSpan |
00:00:00 (disabled) |
Maximum wall-clock time for one execution cycle. When set to 00:00:00 (the default), the timeout is disabled. When the timeout is reached, no more robots will execute, though pending effect continuations will still run. Format: "HH:MM:SS" or "d.HH:MM:SS" for days. |
Note that the Timeout option governs the entire execution cycle. It applies to the total time spent processing the cycle, including Prime robots, the main activity, regular robots, Terminator robots, and effect continuations.
Below is an example configuration which increases the robot limit to 512 and sets a timeout of 5 seconds.
{
"DCR": {
"Workflow": {
"Runtime": {
"MaxRobots": 256,
"Timeout": "00:00:05"
}
}
}
}
