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 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.
echo "Job $JOB_KEY$, Seq $JOB_SEQ$, Name $JOB_NAME$" >"c:\temp\$JOB_SEQ$_success_$JOB_KEY$_$JOB_NAME$.log" |
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:
The following environment variables are set prior to running the command
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.
In the following example command, I would have a python Host Script in the metadata named 'my_python_notify_script' which performs a notification based on two args, the job status and the email to notify. In the Success command I would pass an arg of 'success' and in the Failure command I can pass an arg of 'failed' so that the script can determine what the status is. The script itself will have access to the appropriate environment variables to construct a suitable email that informs of the failure or success.
python "WSL_SCRIPT_my_python_notify_script_CODE" "success" "job-admin@mydomain.com" |
When a Success or Failure Command is triggered RED will do the following:
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. |