DNN Version: 9.0.1
Issue / Request
We are trying to run a task at a specific time every day (for example 5:00AM). The scheduler and the task run fine, but we are having an issue with the next runtime of the task.
It looks like the DNN process sets the next run time to start at the end time of the present task:
For example, if I have a job set to run every 24 hours, and if the task starts at 5AM and ends at 5:10AM, then the DNN process sets the next run time to start at 5:10AM the following day.
How can we make sure the job runs at 5:00 AM every day?
Solution
Use the following code in order to standardize the start times for subsequent tasks:
public override void DoWork()
{
try
{
//notification that the event is progressing
Progressing(); //OPTIONAL
ScheduleHistoryItem taskToSynchronize= CBO.FillCollection<ScheduleHistoryItem>(DotNetNuke.Data.DataProvider.Instance().ExecuteReader("Synchronizetask", "Purge Log Buffer")).FirstOrDefault();
taskToSynchronize.NextStart = DateTime.Today.AddDays(5);
SchedulingController.UpdateScheduleHistory(taskToSynchronize);
ScheduleHistoryItem.Succeeded = true; //REQUIRED
}
....
}
Stored Procedure should look like this:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE SynchronizeTask
@TaskName nvarchar(256)
AS
BEGIN
SELECT TOP 1 * FROM ScheduleHistory
WHERE ScheduleID = (SELECT TOP 1 ScheduleID FROM Schedule WHERE FriendlyName = @TaskName)
ORDER BY StartDate DESC
END
GO
Priyanka Bhotika
Comments