private static void RunBackgroundTask(BackgroundTask backgroundTask) { UserInfo user = PackageController.GetPackageOwner(backgroundTask.PackageId); SecurityContext.SetThreadPrincipal(user.UserId); var schedule = SchedulerController.GetScheduleComplete(backgroundTask.ScheduleId); backgroundTask.Guid = TaskManager.Guid; backgroundTask.Status = BackgroundTaskStatus.Run; TaskController.UpdateTask(backgroundTask); try { var objTask = (SchedulerTask)Activator.CreateInstance(Type.GetType(schedule.Task.TaskType)); objTask.DoWork(); } catch (Exception ex) { TaskManager.WriteError(ex, "Error executing scheduled task"); } finally { try { TaskManager.CompleteTask(); } catch (Exception) { } } }
static void RunSchedule(SchedulerJob schedule, bool changeNextRun) { // update next run (if required) if (changeNextRun) { SchedulerController.CalculateNextStartTime(schedule.ScheduleInfo); } // disable run once task if (schedule.ScheduleInfo.ScheduleType == ScheduleType.OneTime) { schedule.ScheduleInfo.Enabled = false; } Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks(); if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId)) { // this task should be run, so // update its last run schedule.ScheduleInfo.LastRun = DateTime.Now; } // update schedule SchedulerController.UpdateSchedule(schedule.ScheduleInfo); // skip execution if the current task is still running if (scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId)) { return; } // run the schedule in the separate thread schedule.Run(); }
public static void ScheduleTasks() { nextSchedule = SchedulerController.GetNextSchedule(); // set timer if (nextSchedule != null) { if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now) { // this will put the timer to sleep scheduleTimer.Change(Timeout.Infinite, Timeout.Infinite); // run immediately RunNextSchedule(null); } else { // set timer TimeSpan ts = nextSchedule.ScheduleInfo.NextRun.Subtract(DateTime.Now); if (ts < TimeSpan.Zero) { ts = TimeSpan.Zero; // cannot be negative ! } // invoke after the timespan scheduleTimer.Change((long)ts.TotalMilliseconds, Timeout.Infinite); } } }
public ScheduleTaskViewConfiguration GetScheduleTaskViewConfiguration(string taskId, string environment) { List <ScheduleTaskViewConfiguration> configurations = SchedulerController.GetScheduleTaskViewConfigurations(taskId); return(configurations.Find(delegate(ScheduleTaskViewConfiguration configuration) { return configuration.Environment == environment; })); }
public static void ScheduleTasks() { RunManualTasks(); nextSchedule = SchedulerController.GetNextSchedule(); if (nextSchedule != null) { if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now) { RunNextSchedule(null); } } }
public List <ScheduleTaskViewConfiguration> GetScheduleTaskViewConfigurations(string taskId) { return(SchedulerController.GetScheduleTaskViewConfigurations(taskId)); }
public List <ScheduleTaskParameterInfo> GetScheduleParameters(string taskId, int scheduleId) { return(SchedulerController.GetScheduleParameters(taskId, scheduleId)); }
public ScheduleInfo GetSchedule(int scheduleId) { return(SchedulerController.GetSchedule(scheduleId)); }
public DataSet GetSchedulesPaged(int packageId, bool recursive, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) { return(SchedulerController.GetSchedulesPaged(packageId, recursive, filterColumn, filterValue, sortColumn, startRow, maximumRows)); }
public DataSet GetSchedules(int userId) { return(SchedulerController.GetSchedules(userId)); }
public List <ScheduleTaskInfo> GetScheduleTasks() { return(SchedulerController.GetScheduleTasks()); }
public int DeleteSchedule(int scheduleId) { return(SchedulerController.DeleteSchedule(scheduleId)); }
public int UpdateSchedule(ScheduleInfo schedule) { return(SchedulerController.UpdateSchedule(schedule)); }
public int AddSchedule(ScheduleInfo schedule) { return(SchedulerController.AddSchedule(schedule)); }
public int StopSchedule(int scheduleId) { return(SchedulerController.StopSchedule(scheduleId)); }
public DateTime GetSchedulerTime() { return(SchedulerController.GetSchedulerTime()); }
static void RunSchedule(SchedulerJob schedule, bool changeNextRun) { try { // update next run (if required) if (changeNextRun) { SchedulerController.CalculateNextStartTime(schedule.ScheduleInfo); } // disable run once task if (schedule.ScheduleInfo.ScheduleType == ScheduleType.OneTime) { schedule.ScheduleInfo.Enabled = false; } Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks(); if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId)) { // this task should be run, so // update its last run schedule.ScheduleInfo.LastRun = DateTime.Now; } // update schedule int MAX_RETRY_COUNT = 10; int counter = 0; while (counter < MAX_RETRY_COUNT) { try { SchedulerController.UpdateSchedule(schedule.ScheduleInfo); break; } catch (SqlException) { System.Threading.Thread.Sleep(1000); } counter++; } if (counter == MAX_RETRY_COUNT) { return; } // skip execution if the current task is still running 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) { } } }