Control Flows
A control flow performs a series of tasks in sequence. It begins executing at a Start step and continues through connected steps until it finishes at a step that has no more outbound hops. Usually control flows are constructed such that every possible execution path ends in a Finish step or an Abort step, to explicitly mark the end of the flow.
basic control flow structure
Configuration
Imports
Imports are bringing libraries and values from tweakflow modules into flow scope. The imported libraries are available in the entire flow, and can be used in all expressions.
- import standard libraries from
'std'
- import tweastreet libraries from
'tweakstreet/<library name>'
- import from your own modules using a path relative to the flow location such as
'./modules/my_module.tf'
An example import section might look like this:
# import the standard library
import core, data, strings, time, math, fun, locale, regex, bin, decimals from 'std';
# import additional json library
import json from 'tweakstreet/json';
Parameters
Parameters are named expression values that can be passed in when executing a flow. Parameter values are available in the entire flow. They are declared with default values which are used when the flow is invoked without specifying a value for a parameter.
Variables
Flow variables are named expression values that are available in the entire flow. They are typically used to specify flow-wide constants. They are also a good place to validate parameters, or calculate derived values from parameters.
Services
Services are named expression values that are available in the entire flow. They describe various kinds of resources or configuration such as database connections, server credentials, etc.
Specifying these items in the services section of the flow makes it easier to define them and reference them when configuring steps to use them.
Provided variables
Flows provide data about themselves in additional flow variables.
Execution model
Control flows always start executing at their start step.
When a step executes, it performs its task, and selects one of its output gates to move on to the next step. Most steps do not make branching decisions and only have a single out gate. Steps that do support branching decisions have a corresponding set of gates and select exactly one gate through which to continue.
The control record
The control record is a dict value that is carried along the execution path. It is initialized as an empty dict at the start step, and subsequent steps have the opportunity to read, add, remove and replace fields. This mechanism allows steps to record information subsequent steps can access.
Execution success
A control flow finishes successfully after executing a step that has no more outbound hops. You can use the Finish step to make the intended end of execution explicit, and possibly set a result value.
You can use the Abort step to explicitly fail flow execution. When a flow fails, it does not provide a result value.
Execution results
Control flows that finish successfully may provide a return value called the result. By default the result value is nil
. The Finish step can set the result value explicitly. When running a flow through the Run Flow step, the flow result value is made available as one of the step results.
A flow that fails does not provide a result value, it is always nil
.