public static int StopSchedule(int scheduleId) { int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo); if (accountCheck < 0) { return(accountCheck); } SchedulerJob schedule = GetScheduleComplete(scheduleId); if (schedule == null) { return(0); } foreach (BackgroundTask task in TaskController.GetScheduleTasks(scheduleId)) { task.Status = BackgroundTaskStatus.Stopping; TaskController.UpdateTask(task); } return(0); }
public static int StartSchedule(int scheduleId) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo); if (accountCheck < 0) { return(accountCheck); } SchedulerJob schedule = GetScheduleComplete(scheduleId); if (schedule == null) { return(0); } if (TaskController.GetScheduleTasks(scheduleId).Any(x => x.Status == BackgroundTaskStatus.Run || x.Status == BackgroundTaskStatus.Starting)) { return(0); } var parameters = schedule.ScheduleInfo.Parameters.Select( prm => new BackgroundTaskParameter(prm.ParameterId, prm.ParameterValue)).ToList(); var userInfo = PackageController.GetPackageOwner(schedule.ScheduleInfo.PackageId); var backgroundTask = new BackgroundTask( Guid.NewGuid(), Guid.NewGuid().ToString("N"), userInfo.OwnerId == 0 ? userInfo.UserId : userInfo.OwnerId, userInfo.UserId, "SCHEDULER", "RUN_SCHEDULE", schedule.ScheduleInfo.ScheduleName, schedule.ScheduleInfo.ScheduleId, schedule.ScheduleInfo.ScheduleId, schedule.ScheduleInfo.PackageId, schedule.ScheduleInfo.MaxExecutionTime, parameters) { Status = BackgroundTaskStatus.Starting }; TaskController.AddTask(backgroundTask); // update next run (if required) CalculateNextStartTime(schedule.ScheduleInfo); // disable run once task if (schedule.ScheduleInfo.ScheduleType == ScheduleType.OneTime) { schedule.ScheduleInfo.Enabled = false; } schedule.ScheduleInfo.LastRun = DateTime.Now; UpdateSchedule(schedule.ScheduleInfo); return(0); }