示例#1
0
        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)
                {
                }
            }
        }
示例#2
0
        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();
        }
示例#3
0
        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);
                }
            }
        }
示例#4
0
        public ScheduleTaskViewConfiguration GetScheduleTaskViewConfiguration(string taskId, string environment)
        {
            List <ScheduleTaskViewConfiguration> configurations = SchedulerController.GetScheduleTaskViewConfigurations(taskId);

            return(configurations.Find(delegate(ScheduleTaskViewConfiguration configuration)
            {
                return configuration.Environment == environment;
            }));
        }
示例#5
0
        public static void ScheduleTasks()
        {
            RunManualTasks();

            nextSchedule = SchedulerController.GetNextSchedule();

            if (nextSchedule != null)
            {
                if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now)
                {
                    RunNextSchedule(null);
                }
            }
        }
示例#6
0
 public List <ScheduleTaskViewConfiguration> GetScheduleTaskViewConfigurations(string taskId)
 {
     return(SchedulerController.GetScheduleTaskViewConfigurations(taskId));
 }
示例#7
0
 public List <ScheduleTaskParameterInfo> GetScheduleParameters(string taskId, int scheduleId)
 {
     return(SchedulerController.GetScheduleParameters(taskId, scheduleId));
 }
示例#8
0
 public ScheduleInfo GetSchedule(int scheduleId)
 {
     return(SchedulerController.GetSchedule(scheduleId));
 }
示例#9
0
 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));
 }
示例#10
0
 public DataSet GetSchedules(int userId)
 {
     return(SchedulerController.GetSchedules(userId));
 }
示例#11
0
 public List <ScheduleTaskInfo> GetScheduleTasks()
 {
     return(SchedulerController.GetScheduleTasks());
 }
示例#12
0
 public int DeleteSchedule(int scheduleId)
 {
     return(SchedulerController.DeleteSchedule(scheduleId));
 }
示例#13
0
 public int UpdateSchedule(ScheduleInfo schedule)
 {
     return(SchedulerController.UpdateSchedule(schedule));
 }
示例#14
0
 public int AddSchedule(ScheduleInfo schedule)
 {
     return(SchedulerController.AddSchedule(schedule));
 }
示例#15
0
 public int StopSchedule(int scheduleId)
 {
     return(SchedulerController.StopSchedule(scheduleId));
 }
示例#16
0
 public DateTime GetSchedulerTime()
 {
     return(SchedulerController.GetSchedulerTime());
 }
示例#17
0
        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)
                {
                }
            }
        }