Introduction

Users would like to implement processing of a list of elements:

  • The list is created from some initial job.
  • Each element is processed individually by a number of jobs.
  • Error handling applies in a way that failure of a job to process an element makes the order fail and wait for user intervention. Other mechanisms for error handling can apply, see JS7 - How to apply error handling.

The example is implemented with Bash for Unix, it can be adjusted to other scripting languages such as PowerShell, Python etc.

FEATURE AVAILABILITY STARTING FROM RELEASE 2.5.3

Workflow

Download (upload .json example): pdScriptingProcessList.workflow.json

The implementation makes use of a single workflow:

  • An initial job creates the list of elements.
  • JS7 - Cycle Instruction is configured to repeat an undetermined number of times.
    • A job is included that reads and removes the next element from the list.
    • If the next element is empty, i.e. the list is empty, then the JS7 - Break Instruction is used to make the order leave the cycle and to continue with the next job.
    • The next element is processed by a number of sequential jobs.

Job get-list-of-elements

The job creates the list of elements.

  • Create a bash array with arbitrary values:
    • LIST_OF_ELEMENTS=(6550 9319 2407 7793 3662 5006)
  • Create the listOfElements workflow variable that is assigned the list of elements from a string.
    • echo "listOfElements=${LIST_OF_ELEMENTS[*]}" >> $JS7_RETURN_VALUES
    • The JS7_RETURN_VALUES environment variable is automatically available and holds the path to a temporary file which can be added any number of key=value pairs for workflow variables that can be picked up by subsequent jobs and instructions, for details see JS7 - How to pass variables to subsequent jobs.

Cycle Instruction

The JS7 - Cycle Instruction is introduced to implement looping over the list of elements.

  • The Cycle Instruction is configured to run 24/7 in a cycle with a 1s interval.
  • The cycle will be terminated once the list of elements is empty and the order is caused to leave the cycle by use of the JS7 - Break Instruction, see below.

Job get-element-from-list

The job reads the next element from the list.

  • To this purpose the job maps the value of the listOfElements workflow variable to the LIST_OF_ELEMENTS environment variable.
  • The environment variable will hold a string of values.


The job implementation

  • creates a bash array from the environment variable holding the string of values:
    • ARRAY_OF_ELEMENTS=( ${LIST_OF_ELEMENTS} )
  • creates or updates the processElement workflow variable from the first element of the array and forwards the variable to subsequent jobs.
    • echo "processElement=${ARRAY_OF_ELEMENTS[0]}" >> $JS7_RETURN_VALUES
  • removes the first element from the array and updates the listOfElements workflow variable from remaining elements:
    • echo "listOfElements=${ARRAY_OF_ELEMENTS[@]:1}" >> $JS7_RETURN_VALUES

If Instruction

The JS7 - If Instruction is used to check the value of the processElement workflow variable.

  • If the variable is empty then the JS7 - Break Instruction is executed to make an order leave the cycle as there are no elements left for processing. The order will continue with the next instruction after the cycle.
  • If the variable is non-empty then subsequent jobs are executed to process the element.

Job process-element-step-1

The job processes the next element from the list.

  • To this purpose the job maps the value of the processElement workflow variable to the PRODESS_ELEMENT environment variable.


The job implementation makes use of the next element from its PROCESS_ELEMENT environment variable:

Error Handling

Should errors occur in jobs inside the Cycle Instruction then the order will remain with the failing job instruction and will be set to the FAILED state.

Users can resume a failed order with a number of options:

  • choose the action menu of the failed order and select the Resume operation.
  • the following popup windows is brought forward:

Resuming an Order and modifying Workflow Variables

The above example shows a number of workflow variables that can be modified:

  • variables are displayed with values that are historically specific before starting the failed job.
  • variables can be selected from a checkbox:
    • If a variable is selected then its current value will be used when resuming from the selected position in the workflow.
      • Consider that this will overwrite the historic value of the variable for the targeted workflow position.
      • Users are free to modify the values of variables.
    • If a variable is not selected then it will use the historic value associated with the position in the workflow from which the order will be continued.

Resuming an Order and specifying the Cycle End Time

Users can modify the cycle end time:

  • A period shorter than configured with the Cycle Instruction can be specified.
    • Periods are specified by relative dates, for example 1h (1 hour), 10m (10 minutes), 01:30:00 (1 hour, 30 minutes).
    • Specifying a value 0 for the period will cause the order to continue from the resumed position in the workflow, to execute subsequent jobs and to leave the cycle next time it meets the Cycle Instruction.
  • A period that is specified longer than configured with the Cycle Instruction will be ignored

Resuming an Order from a specific Job or Instruction

Users can use the mouse to drag & drop the failed order - indicated by the red bullet - to an earlier or later position in the cycle.

If the order position is not modified then the order will be resumed from its current position. 

Further Resources