This sample shows how to link two jobs using a Job Trigger.
In this example, the Job 3 waits for successful completion of both Job 1 and Job 2.
using (var session = Scheduler.Connect(".", LoginAuthenticationType.Windows, "", "")) | |
{ | |
using (var context = session.NewDataContext()) | |
{ | |
//retrieve the jobs | |
var job1=context.GetJob("Job 1"); | |
var job2 = context.GetJob("Job 2"); | |
var job3 = context.GetJob("Job 3"); | |
//create a Job Trigger | |
var jobTrigger = context.CreateObject(ClassID.JobTrigger) as JobTrigger; | |
jobTrigger.TriggerOptions = JobTriggerOptions.WaitForAll; | |
//create and add a JobTriggerTarget for each of the jobs that you need to wait on | |
var target=context.CreateObject(ClassID.JobTriggerTarget) as JobTriggerTarget; | |
target.TargetJobOID=job1.OID; | |
target.TargetInstance= JobConditionInstance.MostRecentSinceLastExecution; | |
target.TriggerType = JobTriggerType.JobSucceeded; | |
jobTrigger.Targets.Add(target); | |
target = context.CreateObject(ClassID.JobTriggerTarget) as JobTriggerTarget; | |
target.TargetJobOID = job2.OID; | |
target.TargetInstance = JobConditionInstance.MostRecentSinceLastExecution; | |
target.TriggerType = JobTriggerType.JobSucceeded; | |
jobTrigger.Targets.Add(target); | |
job3.Triggers.Add(jobTrigger); | |
job3.Save(); | |
} | |
} |