Process Definitions: Actions Tab

The Actions tab lets you assign one or more actions to be executed when a process reaches a certain stage in its life cycle. The most common use for Process Definition actions is to set the final process status. For example, you can change a process' status to Completed even if the process reached status Error. Actions can be simple, or you can define a set of conditions that must be met before an action makes a change.

Note: You must understand Process States to understand when actions fire.

Note: Actions require RedwoodScript, which in turn requires an Module.Scriptinglicense key.

Actions can fire at the following points in a process' life cycle.

Name Description
On Change

Actions assigned here can fire when the status of a process changes, as long as the process has not yet reached Queued. An action at this point can change the process' scheduled start time, change its Queue, or change the process of the status to Held. Note that an action in this category does not fire when the status changes to Chained.

Pre Running

Actions assigned here can fire before a process has started running, while it has a status of Queued, Dispatched, EventWait, or LockWait. An action at this point can change the process' scheduled start time, change its Queue, or change the process of the status to Held

Post Running

Actions assigned here fire when a process has completed, and allow you to change the final state of the process. An action assigned here is triggered by any transition from Running into a final state (Error, Completed, Killed, Unknown, or Canceled.)

Note: The above uses are only the most common. It is also possible to submit another process in any of the actions, or even cancel the process in question if it has not reached status Running.

The source of the actions is written in RedwoodScript. All actions have access to the process changing status, the old and new statuses, and a jcsSession. All actions generate a log file, which will be attached to the process if it is not empty. When an error occurs in an action, the process will go to status Error. You can set verbosity levels in the Submit Wizard for the stdout.log and stderr.log files.

Tip: If you want to interact with processes from many processes, it might be easier to use a trigger.

Variables

The following variables are available in the Variables list for use in actions. To add a variable to the Source field, click its name.

Before Process On Change

Object Class Example Code
jcsOutLog com.redwood.scheduler.infrastructure.logging.api.Logger jcsOutLog.warning("This is a warning!");
jcsOnChangeContext com.redwood.scheduler.api.scripting.variables.PreExecutingActionScriptObject jcsOnChangeContext.setFailJobOnError(false);
jcsSession com.redwood.scheduler.api.model.SchedulerSession jcsSession.getUserName();
jcsJob com.redwood.scheduler.api.model.Job jcsJob.hold();
jcsOut java.io.PrintWriter jcsOut.println("This text will be printed to a specific output file on the process.");

Before Process Pre Running

Object Class Example Code
jcsOutLog com.redwood.scheduler.infrastructure.logging.api.Logger jcsOutLog.info("This is an informational message!");
jcsSession com.redwood.scheduler.api.model.SchedulerSession jcsSession.getQueueByName("UNIX_Generic");
jcsJob com.redwood.scheduler.api.model.Job jcsJob.hold();
jcsPreRunningContext com.redwood.scheduler.api.scripting.variables.PreExecutingActionScriptObject

jcsOut java.io.PrintWriter jcsOut.println("This text will be printed to a specific output file on the process.");

Before Process Post Running

Object Class Example Code
jcsOutLog com.redwood.scheduler.infrastructure.logging.api.Logger jcsOutLog.debug("This is a debug message!");
jcsPostRunningContext com.redwood.scheduler.api.scripting.variables.PostRunningActionScriptObject

jcsSession com.redwood.scheduler.api.model.SchedulerSession

jcsJob com.redwood.scheduler.api.model.Job jcsJob.restart();
jcsOut java.io.PrintWriter jcsOut.println("This text will be printed to a specific output file on the process.");

The Raise Events tab of the Process Definition editing pop-up window includes the following controls for each action trigger state.

Field Description
Enabled Lets you enable or disable the action.
Action Subject

The user under which the action should run.

Source The source code of the action in RedwoodScript.

Example

Assume that a multi-Step Chain Definition has a process in a Step that may fail, but the rest of the Chain must finish to clean up. The status of the Chain should be Completed if all Steps reach Completed, or Error if a specific Step reaches Error status. The Status Handler on the Step for status Error is Continue. The following action is used to check if the Step reached status Error, and if so, throws a RuntimeException to force the Chain into Error status.

Copy
{
  //Check if the first step failed, if it did,
  //throw an exception to put the Jobchain process into Error

  String stepName = "Run SystemBackup";
  String statusName = "Error";

  // Get an iterator over the child processes of the chain process
  for (Job job : jcsJob.getChildJobs())
  {
    String sName = (String) job.getDescription();
    String sStatus = (String) job.getStatus().name();

    if (stepName.equals(sName) && statusName.equals(sStatus))
    {
      throw new RuntimeException();
    }
  }
}

See Also