Starting Parallel Runs

Learn how to start parallel runs in Kognitos.

Introduction

In Kognitos, processes can call other processes. A parent process can call multiple instances of a subprocess simultaneously, allowing them to run in parallel in new execution environments.

            Parent Process
                  │
     ┌------------┴------------┐
     │            │            │
     │            │            │
Subprocess    Subprocess    Subprocess

How Can I Start Parallel Runs?

This section explains how to start parallel runs by calling multiple instances of a subprocess with examples.

📘

Preface Your Automation with learn "internal.run"

To use this functionality, include learn learn "internal.run" at the beginning of your automation.

Syntax

process each {item} as follows:
    start a run where
        the procedure is "{subprocess name}"
        {input}

Parameters

  1. item: Object to loop over.
  2. subprocess name: The name of the subprocess.
  3. input: Objects to pass to the subprocess, if necessary.

Example

the items are "apples", "flour", "eggs", "milk"
process each item as follows
    start a run where
        the procedure is "to make apple pie"
        the ingredient is the item

Click here to walk through an end-to-end example.

🚧

Remember to Publish Your Process

You need to promote your automation from the Playground to a Process in order to start parallel runs. This applies to both the main parent process and the subprocess. Otherwise, you will get an Assertion Error saying procedure not found.

Handling Subprocess Runs

A parent process can explicitly wait for the runs of a subprocess. By waiting for completion, a parent process can also collect the facts and outputs from all the subprocess runs.

Adding an Explicit Wait

To add an explicit wait, include the following line into your automation after invoking subprocesses:

wait for the runs

Once this is executed, a tab will appear in the user interface, allowing you to view the status of each individual run.

Customizing the Wait Time

The default wait time is 5 seconds per interval. To adjust the wait time, set a custom retry wait count before invoking subprocesses. Here, intervals represents the number of 5-second counts.

the department's max retry wait count is {intervals}

For example, setting intervals to 3 will result in a total wait time of 15 seconds (3 x 5 seconds).

the department's max retry wait count is 3

Getting Output From Subprocess Runs

In order to get output from the subprocess runs, you must add an explicit get into your automation after adding a wait.

Syntax

get the runs's {thing}

Here, the thing is the output you would like to retrieve.

Example

get the runs's greeting

🚧

Note: Matching Parent and Subprocess Output

The get call in the parent process must match the name of the fact used in the subprocess when retrieving output.

  • Example: If the subprocess fact is named status, the parent process should retrieve it using get the runs's status.
  • Automatic Pluralization: If there are multiple runs, the system will automatically pluralize the output in the parent process (e.g., statuses).

Walkthrough: Run Parallelization

This is an example walkthrough of invoking multiple instances of a subprocess in parallel runs.

Parent Process

learn "internal.run"
the department's max retry wait count is 2
the names are "Eva", "Ivan", "Leo", "Nia", "Zoe"
process each name as follows
	start a run where
		the procedure is "to greet the user"
		the user is the name 
wait for the runs
get the runs's greeting
Line #Description
Line 1Necessary syntax for starting parallel runs
Line 2The wait count is set to 10 seconds (2 intervals of 5 seconds).
Line 3A fact is defined as a list of names.
Line 4Initiates a loop across the list of names.
Line 5Initiates subprocess invocation using start a run where syntax.
Line 6Specifies the name of the published subprocess to call.
Line 7Passes input to the subprocess: the name is passed as the user.
Line 8Sets an explicit wait for the subprocess runs.
Line 9Explicitly retrieves the greeting output from the subprocess runs.

Subprocess

Line #Description
Line 1A fact is defined as a string that says "Hello "
Line 2The user is added to the end of the greeting.
Line 3The automation outputs a greeting with the user's name at the end.

Subprocess Output

In line 9, the greetings is referenced as output from the subprocess runs. The results are:

  • Hello Eva
  • Hello Ian
  • Hello Leo
  • Hello Nia
  • Hello Zoe

Additionally, each individual run can be clicked through in the platform: