Actions Tab
The Actions tab lets you assign one or more Actions to be executed when a Job reaches a certain stage in its life cycle. The most common use for Actions is to set the final Job status. For example, you can change a Job's status to Completed even if it ended in Error status. 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 Job Statuses to understand when Actions fire.
Note: Actions require RedwoodScript, which in turn requires an Module.Scripting license key.
Actions can fire at the following points in a Job's lifecycle.
Name | Description |
---|---|
On Change |
Actions assigned here can fire when the status of a Job changes, as long as it has not yet reached Queued status. An Action at this point can change the Job's scheduled start time, change its Queue, or change its status to Held. Note that an Action in this category does not fire when the status changes toChained. |
Pre Running |
Actions assigned here can fire before a Job has started running, while it has a status of Queued, Dispatched, EventWait, or LockWait. An Action at this point can change the Job's scheduled start time, change its Queue, or change its status to Held. |
Post Running |
Actions assigned here fire when a Job has completed, and allow you to change the final state of the Job. 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 run another Job or Workflow Definition in an Action, or even cancel a Job if it has not reached status Running.
The source code for Actions is written in RedwoodScript. All actions have access to the Job or Workflow Definition, the old and new statuses, and a jcsSession
.
All Actions generate a log file, which will be attached to the Job if it is not empty.
When an error occurs in an Action, the Job will enter Error status. You can set verbosity levels in the Run Wizard for the stdout.log
and stderr.log
files.
Tip: If you want to interact with many Jobs, 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 Job.");
|
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 Job.");
|
The Raise Events tab of the 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 Workflow Definition has a Job Call in a Step that may fail, but the rest of the Workflow must finish to clean up. The status of the Job 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 can check if the Step reached status Error, and if so, throw a RuntimeException
to force the Workflow into Error status.
{
//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();
}
}
}