When running scheduled jobs from WhereScape RED, it's possible to configure a job to run commands when the job finishes successfully or when a task in the job fails. These commands can be set to trigger email notifications, maintenance tasks, create a log file, or other actions. 

The commands can be entered in the Job Definition screen as shown below. It is important to make sure the commands you enter reflect the operating system (Linux or Windows) where the job will run or be portable between environments, as the commands entered are simply run as a system command where the job is being executed.

Success Commands

Success commands run when a job is a marked as successful in the final stage of Job execution and the Success Command field is populated. The example used in the Job definition screen above simply outputs the values of the special tokens to a log file which also uses the tokens to form the log file name, thus creating a unique log for each run.

Example:

echo "Job $JOB_KEY$, Seq $JOB_SEQ$, Name $JOB_NAME$" >"c:\temp\$JOB_SEQ$_success_$JOB_KEY$_$JOB_NAME$.log"

Failure Commands

Failure commands run when a task marks a job as failed and the Failure Command field is populated. This command will only run once for the job even if more than one task fails in multi-threaded jobs.

If the Execute Failure Command in event of dependency failure option is set the failure command will also be run when the following conditions are met:

Success and Failure Command Parameters

Special Variables or "Tokens" 

Environment Variables

The following environment variables are set prior to running the command

Success and Failure Command Script Sourcing

RED can reference other scripts form the metadata at run-time, this Script Sourcing feature of RED is also available to be used in the Success and Failure Commands, this allows referencing a Host Script from the RED metadata rather than a script that already exists on the operating system.

Example success command using a Script Sourcing Token:

python "WSL_SCRIPT_my_python_success_script_CODE"

When this Success Command is executed at run-time RED will do the following:

Success and Failure Command Output Protocol

Only the exit code of the Success or Failure command is considered by the Scheduler, all output streams are ignored.

A failure in the Success command execution will not in turn mark the job as a failure as all it's tasks have already completed successfully at this point.