Summary

This article describes how to add conditional logic to adTempus jobs that is based on the type of trigger that started the job.

Background

An adTempus job can have any number of triggers, each of a different kind, and can also be started in other ways (e.g., manual (on-demand) execution). In some cases you may wish to have parts of the job execute only when the job is triggered in a particular way. For example, you may wish to execute a particular Response or Step if the job was started by a File Trigger, but not if it was executed on a schedule.

This can be done using the "ADTTriggerClass" Job Variable that adTempus sets when the job is started, and other Job Variables.

Job Variables 

ADTTriggerClass Job Variable

Each time adTempus starts a job, it sets the "ADTTriggerClass" Job Variable to indicate why the job is being run. This variable will have one of the following values:

JobControlAction
The job was started by a Job Control Action in another job.
RunForSkipped
The job was executed at adTempus startup because a scheduled execution was missed.
Restart
The job was executed at adTempus startup because adTempus was shut down while the previous instance was running.
Manual
The job was started on demand.
ComputerMonitor
The job was started by a Computer Monitor Trigger.
EventLogMonitor
The job was started by an Event Log Monitor Trigger.
EMailTrigger
The job was started by an E-Mail Trigger.
FileTrigger
The job was started by a File Trigger.
JobTrigger
The job was started by a Job Trigger.
ProcessTrigger
The job was started by a Process Trigger.
ScheduleTrigger
The job was started by a Schedule Trigger.
StartupTrigger
The job was started by a Startup Trigger.
WMITrigger
The job was started by a WMI Trigger

Additional Job Variables

In addition to the ADTTriggerClass variable that is automatically set by adTempus, triggers allow you to specify additional Job Variables that are set only for that trigger. For example, if you have two different File Triggers, you can use the Job Variables page of the File Trigger Properties to set a variable that allows you to distinguish which of the two File Triggers triggered the job.

Additionally, each Trigger automatically sets various variables to pass along information about the triggering event. See the Predefined Variables topic for a list of automatic variables.

Using the Job Variables

The Job Variables can be used to add conditional logic to your job, as demonstrated in the following examples.

Conditional Execution of Responses

When you add a Response to a job or job step, that Response is "triggered" by one or more Response Events. For each Response Event, adTempus provides an option to "Use a script to determine whether the Response will be activated." Using such a script, you can check the value of a variable and determine whether the Response should run.

For example, suppose you want to send an e-mail notification message when the job starts, but only if it was triggered by a File Trigger. In the job properties, you add a new Response that executes a Notification Action to send the appropriate notification message. You add an Event to the Response and select the "Job Started" event, so that the Response will run when the job starts.

Now check the Use a script to determine whether the Response will be activated option and click New... to create a new script. In the Script Editor, make sure the language is set to "VB.NET" and replace the template script body with the following script:

Imports System
Imports System.Collections.Generic
Imports ArcanaDevelopment.adTempus.Shared
Imports ArcanaDevelopment.adTempus.ApplicationIntegration

Public Class UserScript
    Inherits ArcanaDevelopment.adTempus.ApplicationIntegration.ResponseEventScriptBase

    Public Overrides Function Run() As Object

        Return adTempus.JobVariables("ADTTriggerClass")="FileTrigger"
    End Function
End Class

Save the script, event, and response.

Each time the job starts, adTempus will evaluate the Response Event and execute this script. The script will return True if the job was started by a File Trigger, causing adTempus to execute the Response. If the job was not started by a File Trigger, the Response will not be executed.

Note: Instead of sending the notification message using a Response, you could also use a Job Step that uses a Notification Task to send the notification message, and configure the step execution to be conditional on the trigger type. See the next section for information on how to do this.

Conditional Execution of Job Steps  

Each Job Step within a Job can have its own Conditions that determine whether the step will run. Using this feature with a Job Variable Condition, you can easily configure a Step to execute only for specific triggers.

For example, instead of using a Response to send a notification message (as in the previous example), you could use a Notification Task as the first step in your job, to send a notification message only if the job is triggered by a File Trigger.

To do this, add a new Job Step that executes a Notification Task, and configure the Notification Task as appropriate. In the Notification Task Properties window, go to the Conditions page.

Under "If condition(s) are not satisfied," select "Skip this step and continue to the next step."

Add a new condition to "Depend on the value of a Job Variable". Configure the condition as follows:

  • Variable to test: "ADTTriggerClass"
  • Comparison Rule: "Equals"
  • Compare To: "FileTrigger"
  • Condition Wait: "Do not wait for condition to be met"

Save the condition.

Now when the job runs, adTempus will check the ADTTriggerClass variable, and will skip the notification step if the job was not triggered by a File Trigger.