Parallel
Overview
Section titled “Overview”The Parallel operation runs several branches at the same time and waits until all of them are done; only then does the workflow go on with the next action. Each branch is a list of actions of its own that run one after the other, just like Actions, including further If, Loop or Parallel.
A typical case: an invoice is uploaded to the SFTP server and then deleted from the inbox folder, and at the same time a mail goes to accounting. One after the other, the mail would wait for the upload; with Parallel the run takes only as long as the slowest branch.
In the visual editor, Parallel shows one column per branch with its name. Add branches in the panel on the right with Add branch, rename or remove them there; add actions with the + in a branch’s column.
Structure
Section titled “Structure”{ "Type": "Parallel", "Name": "Distribute", "Parameters": { "Branches": [ { "Name": "Archive", "Actions": [ { "Type": "FTP", "Name": "Upload", "Parameters": { … } }, { "Type": "SMB", "Name": "CleanUp", "Parameters": { … } } ] }, { "Name": "Notify", "Actions": [ { "Type": "SMTP", "Name": "Accounting", "Parameters": { … } } ] } ], "OnBranchError": "WaitForAll", "MaxConcurrent": 0 }}| Parameter | Default | Meaning |
|---|---|---|
Branches |
– | The branches, each with Name and Actions |
Branches[].Name |
Branch1, Branch2, … |
The branch’s name, unique within the Parallel. Its result is reachable by it; don’t use spaces, dots or braces. |
Branches[].Actions |
– | The branch’s actions, run one after the other |
OnBranchError |
WaitForAll |
What happens when a branch fails: WaitForAll lets the other branches finish, StopOthers cancels them |
MaxConcurrent |
0 (all) |
At most this many branches at the same time; the others wait until one is done |
Run and errors
Section titled “Run and errors”- Inside a branch the same applies as in the
Doof an If: if an action fails, the remaining actions of that branch don’t run. An action’s own error policy applies first, e.g.SkipAction(the branch goes on) orRetry. - A failed branch makes the
Parallelfail as soon as the other branches have finished (WaitForAll) or been cancelled (StopOthers). Then the error policy of theParallelor the workflow decides what happens next, and OnError runs as for any other action. StopOthersstarts no new action in the other branches; an action that is already running is cancelled if it supports that, otherwise it finishes first.- A StopWorkflow action in a branch ends the run: the other branches start no new action afterwards.
- Results from another branch of the same
Parallelmay not be there yet during the run. Use them only in actions after theParallel; otherwise the editor warns. - A Loop in a branch has its own
{{item}},{{index}}and{{count}}, even while a loop runs in another branch at the same time.
Result
Section titled “Result”"Response": { "Branches": { "Archive": { "State": "Completed", "Error": null, "ElapsedMs": 2140.5, "Results": [ { … }, { … } ] }, "Notify": { "State": "Failed", "Error": "Accounting: …", "ElapsedMs": 310.2, "Results": [ { … } ] } }, "CompletedCount": 1, "FailedCount": 1, "CancelledCount": 0}A branch’s State is Completed, Failed or Cancelled (cancelled by StopOthers). Results holds the result of each action of the branch. After the Parallel, a branch result is reachable as {{Distribute.Response.Branches.Archive.State}}, and the results of the actions by their names as usual, e.g. {{Upload.Response…}}.
Example
Section titled “Example”Archive and report an incoming invoice at the same time; if the upload fails, the mail is not waited for but cancelled:
{ "Type": "Parallel", "Name": "Distribute", "Parameters": { "OnBranchError": "StopOthers", "Branches": [ { "Name": "Archive", "Actions": [ { "Type": "FTP", "Name": "Upload", "Parameters": { "Protocol": "SFTP", "Server": "{{connector.Archive.BaseUrl}}", "User": "{{connector.Archive.Username}}", "Password": "{{connector.Archive.Password}}", "Operation": "Upload", "Source": "{{FilePath}}", "Destination": "/invoices/" } } ] }, { "Name": "Notify", "Actions": [ { "Type": "SMTP", "Name": "Accounting", "Parameters": { "SmtpServer": "smtp.example.com", "From": "runos@example.com", "To": "accounting@example.com", "Subject": "New invoice {{FileName}}", "Body": "The invoice {{FileName}} has arrived." } } ] } ] }}