Loops
Automatiqal v0.4+
Task can be executed multiple times by using loop
property. For example if the task is to create 3 tags then the following task can be written:
1 2 3 4 5 6 7 8 9 |
|
Automatiqal
will loop through the values, defined in the loop
property and will run the same operation but replacing {{ item }}
with the currently looped value.
Values
loop
property can contain either:
- array of mixed
string
,numbers
orboolean
- array of objects in format
key: value
, wherevalue
can be mix ofstring
,number
orboolean
Examples:
1 2 3 4 5 |
|
1 2 3 4 5 |
|
The following is NOT allowed since it will mix primitive values and objects:
1 2 3 4 5 |
|
Accessing values
{{ item }}
- will be replaced with the current loop value{{ index }}
- will be replaced with the current index value (First element will be1
){{ item.<key> }}
- when using objects in theloop
property it will be replaced with the<key>
value of the currently looped element. For example:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
While looping Automatiqal
will use the value for the name
property to replace item.name
with.
Context
The loop syntax can be used anywhere in the task. And if object with multiple keys are used then different keys can be used for different purpose.
For example - if we have to publish multiple apps and each app should be published in a different stream then our task can look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Task results
Since tasks with a loop
are ran multiple times then the result of these will be the combined result from all the runs.
In our example above if we want to perform another task, that us using the result from Publish apps
as a source, then this task will be performed on both published apps.
Concurrency
By default the loops are executed in sequence. There is a task option that can overwrite this behavior and run the loops in parallel:
1 2 3 4 5 6 7 8 9 10 11 |
|
When loopParallel
options is explicitly set to true
then the loops will be ran in parallel.
External files
Loop values can be provided by loading external files:
1 2 3 4 5 6 7 8 9 |
|
The example above will read the specified csv file and will loop through it's rows. If the csv have multiple columns then the {{ item.<key> }}
syntax can be used.
Formats
At the moment only 3 file formats are supported: csv
, json
and yaml
CSV files
- can have multiple columns
- should be comma separated
- UTF-8 encoded
JSON files
- contains json array
- UTF-8 encoded
YAML files
- contains array
- UTF-8 encoded
Pause
If needed to pause between the iterations we can use the pause
property:
1 2 3 4 5 6 |
|
In the example above, after each iteration there will be 2.5 seconds pause.