There are several ways you could set this up, depending on how complex your chain is, and how complex your rules are.
I think the most flexible approach is to use conditions that check Shared Schedules, based on the approach in this article. Instead of using conditions on the jobs, you will use conditions on the Responses that link the jobs, so that the Responses will chain the correct jobs on the correct days.
First, create a new Script Library called "ConditionalExecution" with the following code:
Imports System
Imports System.Collections.Generic
Imports ArcanaDevelopment.adTempus.Shared
Imports ArcanaDevelopment.adTempus.ApplicationIntegration
Imports ArcanaDevelopment.adTempus.Client
Public Module ConditionalExecution
Public Function IsTodayInSchedule(scheduleName As String)
Dim session As Scheduler
Try
'connect to the local adTempus server under the identity of the job's user.
session = Scheduler.Connect(".", LoginAuthenticationType.Windows, "", "")
Catch ex As Exception
adTempus.LogMessage(MessageTypeEnum.Error,0,"Could not connect to the adTempus server. Be sure the account the job is running under has permission to connect to adTempus and view the Shared Schedule")
'throw exception so job reports condition evaluation failure
Throw
End Try
Using session
Using context = session.NewDataContext()
Dim schedule = context.GetSharedSchedule(scheduleName)
If schedule Is Nothing Then
adTempus.LogMessage(MessageTypeEnum.Error,0,"Could not find Shared Schedule """ & scheduleName & """")
'throw exception so job reports condition evaluation failure
Throw New Exception("Shared Schedule not found")
End If
If Not schedule.Enabled Then
Return False
End If
Dim today=DateTime.Today
'SharedSchedule doesn't have a method to tell us if a date matches the schedule,
'but it does has a method to get all matching dates for a date range.
'We call that method for today's date, and if the method returns any values
'we know today's date matches the schedule.
Dim matchingDates=schedule.GetMatchingDates(today,today)
If matchingDates.Count>0 Then
Return True
Else
Return False
End If
End Using
End Using
End Function
End Module
Create two Shared Schedules that define the days when Job-1 and Job-2 run. You can call the schedules, for example, "Job 1 Schedule" and "Job 2 Schedule".
Now go to Job-Start. Add a Response with event "Job Succeeded". In the event settings window, check the option to use a script to determine if the response will run. Click New to create a new script.
In the script editor, check the box to include the "ConditionalExecution" script library. Use this script code:
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 ConditionalExecution.IsTodayInSchedule("Job 1 Schedule")
End Function
End Class
Add an Action to the Response to "Control a job or job step" and configure it to run Job-1.
Save the Response. Then duplicate the Response (right-click and choose Duplicate). Edit the new Response and change its script to check "Job 2 Schedule" and change its action to run Job 2.
On Job-2 and Job-3, add a Response to run on success, to trigger Job-3.
On Job-3, add a Response to run on success, to trigger Job-End.
If there are days when neither Job-1 nor Job-2 runs, but you still want Job-End to run after Job-Start, then add a third Response to Job-Start, configured to run Job-End. Its event script should be:
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 Not ConditionalExecution.IsTodayInSchedule("Job 1 Schedule") AndAlso Not ConditionalExecution.IsTodayInSchedule("Job 2 Schedule")
End Function
End Class
Let me know how that goes for you. For adTempus 5 we're looking at new ways to handle job flows like this more easily.