Scheduler fixes
This commit is contained in:
parent
932e77c770
commit
6bd68d4279
3 changed files with 65 additions and 41 deletions
|
@ -40,9 +40,9 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public sealed class Scheduler
|
||||
{
|
||||
static SchedulerJob nextSchedule = null;
|
||||
public static SchedulerJob nextSchedule = null;
|
||||
|
||||
// main timer
|
||||
// main timer and put it to sleep
|
||||
static Timer scheduleTimer = new Timer(new TimerCallback(RunNextSchedule),
|
||||
null,
|
||||
Timeout.Infinite,
|
||||
|
@ -92,6 +92,8 @@ namespace WebsitePanel.EnterpriseServer
|
|||
// this will put the timer to sleep
|
||||
scheduleTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
|
||||
// run immediately
|
||||
RunNextSchedule(null);
|
||||
}
|
||||
|
@ -121,6 +123,10 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
|
||||
static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
|
||||
{
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// update next run (if required)
|
||||
if (changeNextRun)
|
||||
|
@ -142,11 +148,23 @@ namespace WebsitePanel.EnterpriseServer
|
|||
SchedulerController.UpdateSchedule(schedule.ScheduleInfo);
|
||||
|
||||
// skip execution if the current task is still running
|
||||
if (scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
|
||||
return;
|
||||
|
||||
scheduledTasks = TaskManager.GetScheduledTasks();
|
||||
if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
|
||||
{
|
||||
// run the schedule in the separate thread
|
||||
schedule.Run();
|
||||
}
|
||||
}
|
||||
catch (Exception Ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
TaskManager.WriteError(string.Format("RunSchedule Error : {0}", Ex.Message));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,8 +119,14 @@ namespace WebsitePanel.EnterpriseServer
|
|||
finally
|
||||
{
|
||||
// complete task
|
||||
try
|
||||
{
|
||||
TaskManager.CompleteTask();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue