Scheduler service fixes

This commit is contained in:
vfedosevich 2013-05-27 19:10:30 +03:00
parent 2cf0890e14
commit bcceb95f92
3 changed files with 62 additions and 41 deletions

View file

@ -42,18 +42,12 @@ namespace WebsitePanel.EnterpriseServer
public sealed class Scheduler
{
public static SchedulerJob nextSchedule = null;
public static SchedulerJob nextSchedule = null;
private static Timer timer = new Timer(ScheduleTasks, null, 30000, 30000);
public static void Start()
{
var serviceController = new ServiceController("WebsitePanel Scheduler");
if (serviceController != null && serviceController.Status != ServiceControllerStatus.Running)
{
serviceController.WaitForStatus(ServiceControllerStatus.Running);
}
ScheduleTasks(null);
{
ScheduleTasks();
}
public static bool IsScheduleActive(int scheduleId)
@ -82,21 +76,23 @@ namespace WebsitePanel.EnterpriseServer
TaskManager.StopTask(activeTask.TaskId);
}
public static void ScheduleTasks()
{
ScheduleTasks(null);
}
public static void ScheduleTasks(object obj)
{
RunManualTasks();
nextSchedule = SchedulerController.GetNextSchedule();
RunManualTasks();
nextSchedule = SchedulerController.GetNextSchedule();
if (nextSchedule != null)
{
{
if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now)
{
{
RunNextSchedule(null);
}
}
}
Thread.Sleep(30000);
ScheduleTasks(null);
}
private static void RunManualTasks()
@ -155,14 +151,14 @@ namespace WebsitePanel.EnterpriseServer
// call back for the timer function
static void RunNextSchedule(object obj) // obj ignored
{
{
if (nextSchedule == null)
return;
RunSchedule(nextSchedule, true);
// schedule next task
ScheduleTasks(null);
ScheduleTasks();
}
static void RunSchedule(SchedulerJob schedule, bool changeNextRun)