Solution to Update Task Scheduler Start Times to Account for Daylight Savings

NickKroppe
Contributor

Hi, 

This time of year we have the common maintenance point regarding needing to update task scheduler start times to account for daylight savings. It is expected for the platform to not automatically update the task start times to account for daylight savings, thus, this becomes a maintenance point for those companies in states/countries that utilize daylight savings. Until this feature perhaps one day becomes available in the platform, we have a custom solution that will make the maintenance point of this easier for OS administrators. 

You can upload the two files attached in the zip file which will result in uploading an Extender business rule titled "Update_TaskScheduler_StartTimes" and a Data Management job called "Update Task Start Time Daylight Savings".

To use the solution, navigate to the Data Mgmt page and look for the group titled "Task Scheduler Maintenance". Here you will find the Data Mgmt sequence and step you uploaded.

Navigate to the DM step and utilize the Hour Adjustment parameter to push the task start times backwards (-1) or forward (1) one hour. UpdateTasksDaylightSavingsDMStep.png

Once you are happy with the Data Mgmt step setting, go ahead and run the Update Task Start Time Daylight Savings sequence. The sequence will update the task start time for all tasks in the application.

We recommend testing this in a Development application first. Please perform this at your own risk in a Production application.

UpdateTasksDaylightSavingsDMSequence.png 

 

 

12 REPLIES 12

JackLacava
Community Manager
Community Manager

Nice one, Nick!

For the curious, the core of the code looks like this:

Dim dmSchedItem As List(Of DataMgmtScheduleItemEx) = _
	DataMgmtScheduleWcf.GetScheduledJobs(dbConnFW, dbConnApp, False)

For Each schedJob As DataMgmtScheduleItemEx In dmSchedItem

	'adjust the start time based on what the user defines
	schedJob.DataMgmtScheduleItem.StartTime = _
		schedJob.DataMgmtScheduleItem.StartTime.AddHours(Convert.ToDouble(hourAdjustment))

	' Function SaveScheduledJob(dbConnFW As DbConnInfo,dbConnApp As DbConnInfo,isNew As TriStateBool)
	DataMgmtScheduleWcf.SaveScheduledJob( _
		dbConnFW, dbConnApp, schedJob.DataMgmtScheduleItem, TriStateBool.FalseValue)

Next

That surfaces an interesting API to DM jobs that can have interesting applications. Cheers!

Nou
Contributor

Thank you this is very useful information

denisefockler
New Contributor III

@NickKroppe I stumbled across your post here as once again we find ourselves in this predicament - always fun.  Of course I will test this first but I am curious about one item.  Example:  my tasks that are scheduled for 8:30 am and are showing on the task scheduler calendar as 8:30am are kicking off at 9:30 am due to the time change over the weekend.  Therefore, how they look on the calendar is correct but they are just kicking off at a time inconsistent with how they show on the calendar.  Will running the DM jobs you have attached, change how they look on the task scheduler calendar?  I do not want to change the time they are showing as on the calendar.  I just want to sync they time they are kicking off with how they are showing on the calendar.  Does that make sense?

Thank you

Denise

Hi Denise, I'm not 100% sure to be honest. I would suggest to test the solution in a DEV application first to confirm. Are you able to try running the solution to alter task scheduler times in DEV?

I will have to check.  Usually when we refresh Dev with a copy of Production I will delete all the scheduled tasks in Dev as I do not want then running there.  I will have to see if Dev has an old task or two on the calendar that was put there before the time change this past weekend.  Thank you for your help.

I tested in our Dev environment.  I had some old recurring tasks in there.  It moved them on the calendar.  So, if it was a 6am job, it is now showing at 5am on the calendar.  So, I am not sure I want to do this in Production as my jobs are showing the correct time on the calendar.  I saw Jack's response where I think he is suggesting an IIS reset.  I would probably have to wait until this evening to do that but need to fix the jobs before then.  I think what I did last year was opened each one, changed the time from example:  8am to 9am, saved, and then changed back to 8am.

Hi Denise, thank you for testing. I would not execute this in PROD then. We will look into this and see if there is a better solution to retain the correct calendar view and have the task execute at the desired time.

I think Jack may be onto something.  Unfortunately I was not able to test the theory of doing an iis reset to see if that would update the display on the Task Scheduler calendar to show them at the time they were actually executing.  (showing at 8am, scheduled for 8am, but task was starting at 9am).  If an iis reset corrected how they were shown in Task Scheduler then it would have worked to change the times by an hour.  I was not able to do an iis reset until evening and had to get all the tasks back on the right schedule prior to that.  I did open a case with OS Support and was told it was a bug and that I would need to go into each task and edit the task to a start date after the time change.  I think that may have been another part of my issue - my tasks were recurring daily with the time change happening inside the recurring window.  I will have to wait til fall and at that point will probably schedule an iis reset to happen early Sunday morning after the time change.

Thank you

Denise

I don't believe IIS is the answer. That resets daily anyway. I think what is needed is to change the "Start Date" (not the time) in the task scheduler item so that it retains the correct time in the calendar view, and also executes at the desired time based on the time change for the date. I think the best solution for this would be to have the data management solution change the start date for all tasks to the date of when the next time the job will run. This will result in the start date changing to a date that is after the daylight savings change which I expect will resolve the issue. You would ideally want to run this the day before daylight savings or the business day after daylight savings to ensure the start date is changed to a date that is post daylight savings. Try reloading the zip file in my original post to upload the latest version and see if that provides the desired results.

I was able to work with Jack to attach the latest solution in my original post, but here is the new code block that handles the daylights savings logic if anyone would like to review. 

Public Sub UpdateDaylightSavings(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs)
			Try
			
				Using dbConnFW As DBConnInfo = BRApi.Database.CreateFrameworkDbConnInfo(si)
					Using dbConnApp As DBConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
						' Get a list of schedules 
						' Function GetScheduledJobs(dbConnFW As DbConnInfo,dbConnApp As DbConnInfo, getItemsForCurrentUserOnly As Boolean) As List(Of DataMgmtScheduleItem)
						Dim dmSchedItem As List(Of DataMgmtScheduleItemEx)  = DataMgmtScheduleWcf.GetScheduledJobs(dbConnFW,dbConnApp,False)
						For Each schedJob As DataMgmtScheduleItemEx In dmSchedItem
							'adjust the start time based on what the user defines
							schedJob.DataMgmtScheduleItem.StartTime = schedJob.NextRunTime
							' Function SaveScheduledJob(dbConnFW As DbConnInfo,dbConnApp As DbConnInfo,isNew As TriStateBool)
							DataMgmtScheduleWcf.SaveScheduledJob(dbConnFW,dbConnApp,schedJob.DataMgmtScheduleItem,TriStateBool.FalseValue)
						Next
					End Using
				End Using
				Catch ex As Exception
				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
			End Try
		End Sub

 

 

I wonder if restarting the system would make them look consistent with when they actually start. I fear the inconsistency might come from something in the presentation layer not picking up that the switchover happened.

BSipes29
New Contributor III

I have the same question as Denise.  I tested in my Dev application and it does move the time on the Task Scheduler.  My tasks show the correct time in Prod on my Task Scheduler (which were setup before the time change this past weekend) and are now running an hour ahead (8:00 am task ran at 9:00 am).

Please sign in! NickKroppe