Answered Topic How to Trigger multiple jobs in sequence RSS Feed Icon

You must be logged in to reply to this topic.

Avatar
Joined: December 8, 2015
Posts: 8
 

Hello World,

Trigger question:

Let's say I have the following Jobs:

Job-Start Start every day at 17:00 houses

Job-1 triggered [optional] using a Schedule for day 1

Job-2 triggered [optional] using a Schedule for day 2

Job-3   triggered [optional] using a Schedule for day 1 and 2

Job-End When every RUNNING(!) job has ended

So on day 1, I want Job-Start, Job-1, Job-3 to start in sequence ending with Job-End.

On day 2, I want Job-Start, Job-2, Job-3 to start in sequence ending with Job-End.

So Job-2 will not run on day 1 and Job-1 will not run on day 2.

Can I define a relation between my jobs so they will wait on the job(S) before, IF it is scheduled to run?

In other words, I don't want to create dependencies on a daily bases, but in jobs.

Thanks for any help,

Kind regards,

Guy

 

 
Avatar
Joined: December 8, 2015
Posts: 8
 

No worries, no answer needed.

Found the solution :-)

 
Avatar
Arcana Development Staff
Joined: November 6, 2015
Posts: 305
 

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.

 
Avatar
Arcana Development Staff
Joined: November 6, 2015
Posts: 305
 
GuyS wrote:

No worries, no answer needed.

Found the solution :-)

I just saw this after I posted my reply. Please share the solution you used. Maybe it's simpler!

 
Avatar
Joined: December 8, 2015
Posts: 8
 

Hi Bill.

I appologize for not responding earlier to your reply.

Because I found a way to handle the situation, I didn't check the forum anymore.

I will centainly look into your solution, but I must admit that my knowledge of scripting is limitted.

The solution I found was:

Make Schedules for Job-1, Job-2 and Job-3

Create jobs to set variables Run-1, Run-2 and Run-3 to 'Y' using the created Schedules

Run Job-Start on a daily basesAdd triggers and conditions to make a chain of the jobs, but skip the execution if the variable is not correct

If you want an export, let me know.

Thanks for your time and reply.

Sorry I didn't see it right away.

Kind regards,Guy

 
Avatar
Arcana Development Staff
Joined: November 6, 2015
Posts: 305
 
Thanks for the update. I like your solution--it is simpler than mine.
 
You must log in to post.