Scheduling time - when the day falls on non-business day

TJ (32 posts)
January 8, 2020 11:51 AM
Accepted Answer

Hi Support,

I am having dilemma to schedule a job for non-business day. I have some jobs which will be run on the first day or the last day of month, but if that 1st or last day falls on Saturday or Monday, I will still need them to run on the same day but different time. For example, One job has to be run at 6am on the first day of month, but when it falls on Sunday, the system is under maintenance frame 12am-8am. I will want it to be run in the afternoon when that day falls on Sunday. Does Adtempus have this feature to configure it?

 

Thanks in advance,

Tracy 

Bill Staff (599 posts)
January 9, 2020 08:45 AM
Accepted Answer

There are a few ways to do this (see this discussion). One simple way is to use a Script Condition that checks the day/time and enforces the maintenance window.

If your maintenance window on Sunday is 12am to 8am, you would first create a script that checks the day and time:

Go to the Shared Scripts view and create a new script. Name it "Sunday Maintenance Window" and make sure the language is set to "VB.NET". Replace the template code with the following:

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

Public Class UserScript
    Inherits ArcanaDevelopment.adTempus.ApplicationIntegration.UserScriptBase

    Public Overrides Function Run() As Object

        Dim theTime=DateTime.Now
        
        If theTime.DayOfWeek = DayOfWeek.Sunday Then
            'It's Sunday, so check the time.
            
            If theTime.Hour >=0 And theTime.Hour < 8 Then
                'the time is between 12am and 8am, so don't allow the job to run
                Return False
            End If
        End If
        
    
        'otherwise it's outside the maintenance window
        Return True
    End Function
End Class

This script looks at the current date/time. If it's between 12am and 8am on Sunday, it returns False, otherwise it returns True.

Now go edit the job(s) that need to follow this window.

  • On the Conditions page, make sure it's set to "Execute only if all conditions are met" and "Fail the job".
  • Then add a new Script Condition. Click the Select button and select your "Sunday Maintenance Window" script as the script to execute.
  • Go to the Condition Wait tab and set it to "Wait until the condition is met". Change the polling interval to something like 300 seconds (check every 5 minutes). There's no need to have it checking frequently, since you don't need it to run immediately at 8am.
  • Uncheck the box labeled "Once satisfied, do not re-evaluate...". You need this condition to always get re-evaluated if there are other conditions, since it's time-based.

If you have additional maintenance windows, you can modify the script to cover those timeframes as well. For example, this version adds a maintenance window on Saturday from 2am to 11am:

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

Public Class UserScript
    Inherits ArcanaDevelopment.adTempus.ApplicationIntegration.UserScriptBase

    Public Overrides Function Run() As Object

        Dim theTime=DateTime.Now
        
        If theTime.DayOfWeek = DayOfWeek.Sunday Then
            'It's Sunday, so check the time.
            
            If theTime.Hour >=0 And theTime.Hour < 8 Then
                'the time is between 12am and 8am, so don't allow the job to run
                Return False
            End If
        End If
        
        If theTime.DayOfWeek = DayOfWeek.Saturday Then
            'It's Saturday, so check the time.
            
            If theTime.Hour >=2 And theTime.Hour < 11 Then
                'the time is between 2am and 11am, so don't allow the job to run
                Return False
            End If
        End If
        
        'otherwise it's outside the maintenance window
        Return True
    End Function
End Class

Or, if different jobs get different combinations of maintenance windows applied to them, you can create additional Shared Scripts for each maintenance window, and then add additional Script Conditions to the job. For example, if all jobs are subject to the Sunday maintenance window, but only some are subject to the Saturday window, you could create a Saturday Maintenance Window script and a Sunday Maintenance Window script, and apply them to the jobs as appropriate.

Your job will still trigger at its normal scheduled time, but if it's during the maintenance window it will wait (in "Waiting for condition" state) until the maintenance window is over.

Another approach is to define a global Job Variable that indicates whether the system is currently in a maintenance window (or several variables, if there are different windows that apply to different jobs/systems). You would then create jobs to flip the value of these variables at the beginning and end of the maintenance window. For example, have a variable named "InMaintenanceWindow" that is normally set to "false". You schedule a job to run at 12am on Sunday that updates this variable to "true". You schedule a second job at 8am on Sunday to set it back to "false". Then for each job that is affected by the maintenance window, you add a Job Variable Condition that checks the value, and only runs the job once the variable is not "true" (use all the same configuration options as you used for the Script Condition).

Replies are disabled for this topic.