public static void RunScheduleNow(int id) { Schedule schedule = GetSchedule(id); Scheduler.RemoveFromScheduleQueue(schedule); ScheduleHistory scheduleHistory = new ScheduleHistory(schedule); scheduleHistory.NextStart = DateTime.Now.ToString(); schedule.IsEnable = true; Scheduler.AddToScheduleQueue(scheduleHistory); }
public static void RunScheduleItemNow(Schedule schedule) { Scheduler.RemoveFromScheduleQueue(schedule); ScheduleHistory scheduleHistory = new ScheduleHistory(schedule); if (schedule.IsEnable) { Scheduler.AddToScheduleQueue(scheduleHistory); } }
public static void UpdateTaskHistory(ScheduleHistory scheduleHistory) { try { SchedulerDataProvider.UpdateTaskHistory(scheduleHistory); } catch (Exception e) { ErrorLogger.log(scheduleHistory, e, "UpdateTaskHistory"); throw; } }
public static void RunEventSchedule() { try { ScheduleHistory objScheduleHistory = null; List <Schedule> schedules = SchedulerController.GetTasks(); foreach (Schedule schedule in schedules) { objScheduleHistory = new ScheduleHistory(schedule); //check && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && if (!IsInQueue(objScheduleHistory) && !IsInProgress(objScheduleHistory) && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && objScheduleHistory.IsEnable) { objScheduleHistory.Status = null; AddToScheduleQueue(objScheduleHistory); } } while (GetScheduleQueueCount() > 0) { SetScheduleStatus(ScheduleStatus.RUNNING_EVENT_SCHEDULE); //Fire off the events that need running. if (GetScheduleQueueCount() > 0) { FireEvents(true); } if (_writerTimeouts > 20 || _readerTimeouts > 20) { //Wait for 10 minutes so we don't fill up the logs Thread.Sleep(TimeSpan.FromMinutes(10)); } else { //Wait for 10 seconds to avoid cpu overutilization Thread.Sleep(TimeSpan.FromSeconds(10)); } if (GetScheduleQueueCount() == 0) { return; } } } catch (Exception exc) { ErrorLogger.SchedulerProcessException(exc); } }
public static int AddTaskHistory(ScheduleHistory scheduleHistory) { int Id = 0; try { Id = SchedulerDataProvider.AddTaskHistory(scheduleHistory); } catch (Exception) { throw; } return(Id); }
private static bool ScheduleQueueContains(ScheduleHistory objScheduleItem) { try { using (ScheduleQueue.GetReadLock(LockTimeout)) { return(ScheduleQueue.Any(si => si.ScheduleID == objScheduleItem.ScheduleID)); } } catch (ApplicationException ex) { Interlocked.Increment(ref _readerTimeouts); ErrorLogger.SchedulerProcessException(ex); return(false); } }
private static void RemoveFromScheduleInProgress(Schedule scheduleItem) { try { using (ScheduleInProgress.GetWriteLock(LockTimeout)) { ScheduleHistory item = ScheduleInProgress.Where(si => si.ScheduleID == scheduleItem.ScheduleID).SingleOrDefault(); if (item != null) { ScheduleInProgress.Remove(item); } } } catch (ApplicationException ex) { Interlocked.Increment(ref _writerTimeouts); ErrorLogger.SchedulerProcessException(ex); } }
public static void RemoveFromScheduleQueueByID(int ScheduleID) { try { using (ScheduleQueue.GetWriteLock(LockTimeout)) { ScheduleHistory item = ScheduleQueue.Where(si => si.ScheduleID == ScheduleID).SingleOrDefault(); if (item != null) { ScheduleQueue.Remove(item); } } } catch (ApplicationException ex) { Interlocked.Increment(ref _writerTimeouts); ErrorLogger.SchedulerProcessException(ex); } }
//Add a queue request to Threadpool with a //callback to RunPooledThread which calls Run() public void AddQueueUserWorkItem(Schedule s) { numberOfProcessesInQueue += 1; numberOfProcesses += 1; var obj = new ScheduleHistory(s); try { //Create a callback to subroutine RunPooledThread WaitCallback callback = RunPooledThread; //And put in a request to ThreadPool to run the process. ThreadPool.QueueUserWorkItem(callback, obj); Thread.Sleep(1000); } catch (Exception exc) { ErrorLogger.log(s, exc, "AddQueueUserWorkItem"); } }
public static void log(ScheduleHistory history, Exception e, string methodName) { string location = HostingEnvironment.ApplicationPhysicalPath; //HostingEnvironment.ApplicationPhysicalPath string fileDirectory = Path.Combine(location, "ErrorLog"); if (!Directory.Exists(fileDirectory)) { Directory.CreateDirectory(fileDirectory); } string path = fileDirectory + "/ScheduleHistoryExceptionLog.txt"; using (StreamWriter writer = new StreamWriter(path, true)) { lock (obj) { writer.WriteLine(history.FullNamespace + "----- CurrentDate:" + DateTime.Now + "-----StartDate" + history.HistoryStartDate + "-----EndDate" + history.HistoryEndDate); writer.WriteLine("Error Message" + e.Message.ToString() + "-----Error Source" + e.Source.ToString() + "-----Target Site" + e.TargetSite.ToString()); writer.WriteLine("Method Name :-" + methodName + "----------------------------------------------------------------------------------"); } } }
private static void AddToScheduleInProgress(ScheduleHistory scheduleHistoryItem) { if (!(ScheduleInProgressContains(scheduleHistoryItem))) { try { using (ScheduleInProgress.GetWriteLock(LockTimeout)) { if (!(ScheduleInProgressContains(scheduleHistoryItem))) { ScheduleInProgress.Add(scheduleHistoryItem); } } } catch (ApplicationException ex) { // The writer lock request timed out. Interlocked.Increment(ref _writerTimeouts); ErrorLogger.SchedulerProcessException(ex); } } }
public static void UpdateTaskHistory(ScheduleHistory scheduleHistory) { List <KeyValuePair <string, object> > ParameterCollection = new List <KeyValuePair <string, object> >(); ParameterCollection.Add(new KeyValuePair <string, object>("@ScheduleHistoryID", scheduleHistory.ScheduleHistoryID)); ParameterCollection.Add(new KeyValuePair <string, object>("@ScheduleID", scheduleHistory.ScheduleID)); ParameterCollection.Add(new KeyValuePair <string, object>("@StartDate", scheduleHistory.HistoryStartDate)); ParameterCollection.Add(new KeyValuePair <string, object>("@ReturnText", scheduleHistory.ReturnText)); ParameterCollection.Add(new KeyValuePair <string, object>("@EndDate", scheduleHistory.HistoryEndDate)); ParameterCollection.Add(new KeyValuePair <string, object>("@Status", scheduleHistory.Status)); ParameterCollection.Add(new KeyValuePair <string, object>("@NextStart", scheduleHistory.NextStart)); ParameterCollection.Add(new KeyValuePair <string, object>("@Server", scheduleHistory.Server)); try { sagesql.ExecuteNonQuery("usp_ScheduleHistoryUpdate", ParameterCollection); } catch (Exception) { throw; } }
public static void AddToScheduleQueue(ScheduleHistory objScheduleHistory) { if (!ScheduleQueueContains(objScheduleHistory)) { try { using (ScheduleQueue.GetWriteLock(LockTimeout)) { if (!ScheduleQueueContains(objScheduleHistory) && !IsInProgress(objScheduleHistory)) { ScheduleQueue.Add(objScheduleHistory); } } } catch (ApplicationException ex) { // The writer lock request timed out. Interlocked.Increment(ref _writerTimeouts); ErrorLogger.SchedulerProcessException(ex); } } }
public static int AddTaskHistory(ScheduleHistory scheduleHistory) { int id = 0; List <KeyValuePair <string, object> > ParameterCollection = new List <KeyValuePair <string, object> >(); ParameterCollection.Add(new KeyValuePair <string, object>("@ScheduleID", scheduleHistory.ScheduleID)); ParameterCollection.Add(new KeyValuePair <string, object>("@StartDate", scheduleHistory.HistoryStartDate)); ParameterCollection.Add(new KeyValuePair <string, object>("@EndDate", scheduleHistory.HistoryEndDate)); ParameterCollection.Add(new KeyValuePair <string, object>("@Status", scheduleHistory.Status)); ParameterCollection.Add(new KeyValuePair <string, object>("@NextStart", scheduleHistory.NextStart)); ParameterCollection.Add(new KeyValuePair <string, object>("@Server", scheduleHistory.Server)); try { id = sagesql.ExecuteNonQuery("usp_ScheduleHistoryAdd", ParameterCollection, "@id"); } catch (Exception) { throw; } return(id); }
public static void TaskCompleted(TaskBase task) { try { ScheduleHistory objScheduleHistory = task.TaskRecordItem; objScheduleHistory = task.TaskRecordItem; RemoveFromScheduleInProgress(objScheduleHistory); Interlocked.Decrement(ref ActiveThreadCount); objScheduleHistory.HistoryEndDate = DateTime.Now; objScheduleHistory.Status = true; objScheduleHistory.NextStart = SchedulerController.GetNextStart(objScheduleHistory); task.TaskRecordItem.ReturnText = "Successfully completed"; SchedulerController.UpdateTaskHistory(objScheduleHistory); if (!string.IsNullOrEmpty(objScheduleHistory.NextStart)) { objScheduleHistory.HistoryStartDate = null; objScheduleHistory.HistoryEndDate = null; objScheduleHistory.ReturnText = ""; objScheduleHistory.ProcessGroup = -1; objScheduleHistory.Status = false; AddToScheduleQueue(objScheduleHistory); } } catch (Exception exc) { if (task.TaskRecordItem != null) { ErrorLogger.SchedulerProcessException(exc); } } }
private TaskBase GetTaskBase(string strProcess, ScheduleHistory objScheduleHistory) { //This is a method to encapsulate returning //an object whose class inherits TaskBase. Type t = BuildManager.GetType(strProcess, true, true); var param = new ScheduleHistory[1]; param[0] = objScheduleHistory; var types = new Type[1]; //Get the constructor for the Class types[0] = typeof(ScheduleHistory); System.Reflection.ConstructorInfo objConstructor; objConstructor = t.GetConstructor(types); TaskBase taskBase = null; if (objConstructor != null) { taskBase = (TaskBase)objConstructor.Invoke(param); } return(taskBase); }
private static bool ScheduleQueueContains(ScheduleHistory objScheduleItem) { try { using (ScheduleQueue.GetReadLock(LockTimeout)) { return ScheduleQueue.Any(si => si.ScheduleID == objScheduleItem.ScheduleID); } } catch (ApplicationException ex) { Interlocked.Increment(ref _readerTimeouts); ErrorLogger.SchedulerProcessException(ex); return false; } }
public static void TaskErrored(TaskBase task, Exception exception) { try { ScheduleHistory objScheduleHistoryItem = task.TaskRecordItem; RemoveFromScheduleInProgress(objScheduleHistoryItem); Interlocked.Decrement(ref ActiveThreadCount); objScheduleHistoryItem.HistoryEndDate = DateTime.Now; DateTime startedTime = objScheduleHistoryItem.HistoryStartDate ?? DateTime.Now; if (objScheduleHistoryItem.RetryTimeLapse > 0) { switch (objScheduleHistoryItem.RetryFrequencyUnit) { case 1: startedTime.AddSeconds(objScheduleHistoryItem.RetryTimeLapse); break; case 2: startedTime.AddMinutes(objScheduleHistoryItem.RetryTimeLapse); break; case 3: startedTime.AddHours(objScheduleHistoryItem.RetryTimeLapse); break; case 4: startedTime.AddDays(objScheduleHistoryItem.RetryTimeLapse); break; } objScheduleHistoryItem.NextStart = Convert.ToString(startedTime); } objScheduleHistoryItem.Status = false; string error = ""; StringBuilder errorlog = new StringBuilder(); errorlog.AppendLine("Error"); if ((exception != null)) { error = exception.Message; } errorlog.AppendLine(error); task.TaskRecordItem.ReturnText = errorlog.ToString(); SchedulerController.UpdateTaskHistory(objScheduleHistoryItem); if (!string.IsNullOrEmpty(objScheduleHistoryItem.NextStart) && objScheduleHistoryItem.RetryTimeLapse > 0) { objScheduleHistoryItem.HistoryStartDate = null; objScheduleHistoryItem.HistoryEndDate = null; objScheduleHistoryItem.ReturnText = ""; objScheduleHistoryItem.ProcessGroup = -1; AddToScheduleQueue(objScheduleHistoryItem); } } catch (Exception exc) { if (task.TaskRecordItem != null) { ErrorLogger.SchedulerProcessException(exc); } } }
public ApplyCategoryPriceRules(ScheduleHistory scheduleHistory) : base() { base.TaskRecordItem = scheduleHistory; }
public static void UpdateTaskHistory(ScheduleHistory scheduleHistory) { List<KeyValuePair<string, object>> ParameterCollection = new List<KeyValuePair<string, object>>(); ParameterCollection.Add(new KeyValuePair<string, object>("@ScheduleHistoryID", scheduleHistory.ScheduleHistoryID)); ParameterCollection.Add(new KeyValuePair<string, object>("@ScheduleID", scheduleHistory.ScheduleID)); ParameterCollection.Add(new KeyValuePair<string, object>("@StartDate", scheduleHistory.HistoryStartDate)); ParameterCollection.Add(new KeyValuePair<string, object>("@ReturnText", scheduleHistory.ReturnText)); ParameterCollection.Add(new KeyValuePair<string, object>("@EndDate", scheduleHistory.HistoryEndDate)); ParameterCollection.Add(new KeyValuePair<string, object>("@Status", scheduleHistory.Status)); ParameterCollection.Add(new KeyValuePair<string, object>("@NextStart", scheduleHistory.NextStart)); ParameterCollection.Add(new KeyValuePair<string, object>("@Server", scheduleHistory.Server)); try { sagesql.ExecuteNonQuery("usp_ScheduleHistoryUpdate", ParameterCollection); } catch (Exception) { throw; } }
public static string GetNextStartHistory(ScheduleHistory objScheduleHistory) { if (string.IsNullOrEmpty(objScheduleHistory.NextStart) && objScheduleHistory.RunningMode != RunningMode.Once) { objScheduleHistory.NextStart = Convert.ToString(DateTime.Parse(objScheduleHistory.StartDate).AddHours(objScheduleHistory.StartHour).AddMinutes(objScheduleHistory.StartMin)); } switch (objScheduleHistory.RunningMode) { case RunningMode.Hourly: objScheduleHistory.NextStart = Convert.ToString(DateTime.Parse(objScheduleHistory.StartDate).AddHours(objScheduleHistory.EveryHours).AddMinutes(objScheduleHistory.EveryMin)); break; case RunningMode.Daily: objScheduleHistory.NextStart = Convert.ToString(DateTime.Parse(objScheduleHistory.StartDate).AddDays(objScheduleHistory.RepeatDays)); break; case RunningMode.Weekly: int day = GetNextScheduleWeekDay(objScheduleHistory.ScheduleID, (int)DateTime.Parse(objScheduleHistory.StartDate).DayOfWeek + 1); DateTime now = DateTime.Parse(DateTime.Now.ToShortDateString() + " " + objScheduleHistory.StartHour + ":" + objScheduleHistory.StartMin + ":00"); int nextday = 0; int currentstartday = (int)now.DayOfWeek + 1; if (day > currentstartday) nextday = day - currentstartday; else nextday = 7 - currentstartday + day; objScheduleHistory.NextStart = Convert.ToString(now.AddDays(nextday)); break; case RunningMode.WeekNumber: day = GetNextScheduleWeekDay(objScheduleHistory.ScheduleID, (int)DateTime.Parse(objScheduleHistory.StartDate).DayOfWeek + 1); now = DateTime.Parse(DateTime.Now.ToShortDateString() + " " + objScheduleHistory.StartHour + ":" + objScheduleHistory.StartMin + ":00"); nextday = 0; currentstartday = (int)now.DayOfWeek + 1; int nextMonth = now.Month; if (day > currentstartday) { nextday = now.Day + day - currentstartday; } else { nextMonth = SchedulerController.ScheduleDateGetNextMonth(objScheduleHistory.ScheduleID, DateTime.Parse(objScheduleHistory.StartDate).Month); nextday = objScheduleHistory.RepeatWeeks * 7 - 7 + day; } DateTime nextDate = new DateTime(now.Year, nextMonth, nextday); objScheduleHistory.NextStart = Convert.ToString(nextDate); break; case RunningMode.Calendar: objScheduleHistory.NextStart = Convert.ToString(GetNextScheduleDate(objScheduleHistory.ScheduleID, objScheduleHistory.StartDate)); break; case RunningMode.Once: //do nothing break; } return objScheduleHistory.NextStart; }
public static string GetNextStartHistory(ScheduleHistory objScheduleHistory) { if (string.IsNullOrEmpty(objScheduleHistory.NextStart) && objScheduleHistory.RunningMode != RunningMode.Once) { objScheduleHistory.NextStart = Convert.ToString(DateTime.Parse(objScheduleHistory.StartDate).AddHours(objScheduleHistory.StartHour).AddMinutes(objScheduleHistory.StartMin)); } switch (objScheduleHistory.RunningMode) { case RunningMode.Hourly: objScheduleHistory.NextStart = Convert.ToString(DateTime.Parse(objScheduleHistory.StartDate).AddHours(objScheduleHistory.EveryHours).AddMinutes(objScheduleHistory.EveryMin)); break; case RunningMode.Daily: objScheduleHistory.NextStart = Convert.ToString(DateTime.Parse(objScheduleHistory.StartDate).AddDays(objScheduleHistory.RepeatDays)); break; case RunningMode.Weekly: int day = GetNextScheduleWeekDay(objScheduleHistory.ScheduleID, (int)DateTime.Parse(objScheduleHistory.StartDate).DayOfWeek + 1); DateTime now = DateTime.Parse(DateTime.Now.ToShortDateString() + " " + objScheduleHistory.StartHour + ":" + objScheduleHistory.StartMin + ":00"); int nextday = 0; int currentstartday = (int)now.DayOfWeek + 1; if (day > currentstartday) { nextday = day - currentstartday; } else { nextday = 7 - currentstartday + day; } objScheduleHistory.NextStart = Convert.ToString(now.AddDays(nextday)); break; case RunningMode.WeekNumber: day = GetNextScheduleWeekDay(objScheduleHistory.ScheduleID, (int)DateTime.Parse(objScheduleHistory.StartDate).DayOfWeek + 1); now = DateTime.Parse(DateTime.Now.ToShortDateString() + " " + objScheduleHistory.StartHour + ":" + objScheduleHistory.StartMin + ":00"); nextday = 0; currentstartday = (int)now.DayOfWeek + 1; int nextMonth = now.Month; if (day > currentstartday) { nextday = now.Day + day - currentstartday; } else { nextMonth = SchedulerController.ScheduleDateGetNextMonth(objScheduleHistory.ScheduleID, DateTime.Parse(objScheduleHistory.StartDate).Month); nextday = objScheduleHistory.RepeatWeeks * 7 - 7 + day; } DateTime nextDate = new DateTime(now.Year, nextMonth, nextday); objScheduleHistory.NextStart = Convert.ToString(nextDate); break; case RunningMode.Calendar: objScheduleHistory.NextStart = Convert.ToString(GetNextScheduleDate(objScheduleHistory.ScheduleID, objScheduleHistory.StartDate)); break; case RunningMode.Once: //do nothing break; } return(objScheduleHistory.NextStart); }
public static int AddTaskHistory(ScheduleHistory scheduleHistory) { int Id = 0; try { Id = SchedulerDataProvider.AddTaskHistory(scheduleHistory); } catch (Exception) { throw; } return Id; }
public static void RunScheduleItemNow(Schedule schedule) { Scheduler.RemoveFromScheduleQueue(schedule); ScheduleHistory scheduleHistory = new ScheduleHistory(schedule); if (schedule.IsEnable) Scheduler.AddToScheduleQueue(scheduleHistory); }
public TaskBase(ScheduleHistory scheduleHistory) { this.TaskRecordItem = scheduleHistory; }
public static void RunEventSchedule() { try { ScheduleHistory objScheduleHistory = null; List<Schedule> schedules = SchedulerController.GetTasks(); foreach (Schedule schedule in schedules) { objScheduleHistory = new ScheduleHistory(schedule); //check && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && if (!IsInQueue(objScheduleHistory) && !IsInProgress(objScheduleHistory) && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && objScheduleHistory.IsEnable) { objScheduleHistory.Status = null; AddToScheduleQueue(objScheduleHistory); } } while (GetScheduleQueueCount() > 0) { SetScheduleStatus(ScheduleStatus.RUNNING_EVENT_SCHEDULE); //Fire off the events that need running. if (GetScheduleQueueCount() > 0) { FireEvents(true); } if (_writerTimeouts > 20 || _readerTimeouts > 20) { //Wait for 10 minutes so we don't fill up the logs Thread.Sleep(TimeSpan.FromMinutes(10)); } else { //Wait for 10 seconds to avoid cpu overutilization Thread.Sleep(TimeSpan.FromSeconds(10)); } if (GetScheduleQueueCount() == 0) { return; } } } catch (Exception exc) { ErrorLogger.SchedulerProcessException(exc); } }
public static void Start() { for (int i = 0; i <= 30; i++) { Thread.Sleep(1000); } try { ActiveThreadCount = 0; while (KeepRunning) { try { ForceReloadSchedule = false; ScheduleHistory objScheduleHistory = null; List<Schedule> schedules = SchedulerController.GetTasks(); foreach (Schedule schedule in schedules) { objScheduleHistory = new ScheduleHistory(schedule); //check && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && if (!IsInQueue(objScheduleHistory) && !IsInProgress(objScheduleHistory) && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && objScheduleHistory.IsEnable) { objScheduleHistory.Status = null; AddToScheduleQueue(objScheduleHistory); } } DateTime lastQueueRefresh = DateTime.Now; bool refreshQueueSchedule = false; while (FreeThreads > 0 && KeepRunning && !ForceReloadSchedule) { if (GetScheduleQueueCount() > 0) { FireEvents(true); } if (KeepThreadAlive == false) { return; } if (_writerTimeouts > 20 || _readerTimeouts > 20) { if (KeepRunning) { Thread.Sleep(TimeSpan.FromMinutes(10)); } else { return; } } else { if (KeepRunning) { Thread.Sleep(TimeSpan.FromSeconds(10)); } else { return; } if ((lastQueueRefresh.AddMinutes(10) <= DateTime.Now || ForceReloadSchedule) && FreeThreads == _maxThreadCount) { refreshQueueSchedule = true; break; } } } if (KeepRunning) { if (refreshQueueSchedule == false) { SetScheduleStatus(ScheduleStatus.WAITING_FOR_OPEN_THREAD); Thread.Sleep(10000); //sleep for 10 seconds } } else { return; } } catch (Exception exc) { ErrorLogger.SchedulerProcessException(exc); //sleep for 10 minutes Thread.Sleep(600000); } } } finally { SetScheduleStatus(ScheduleStatus.STOPPED); KeepRunning = false; ActiveThreadCount = 0; } }
public static void Start() { for (int i = 0; i <= 30; i++) { Thread.Sleep(1000); } try { ActiveThreadCount = 0; while (KeepRunning) { try { ForceReloadSchedule = false; ScheduleHistory objScheduleHistory = null; List <Schedule> schedules = SchedulerController.GetTasks(); foreach (Schedule schedule in schedules) { objScheduleHistory = new ScheduleHistory(schedule); //check && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && if (!IsInQueue(objScheduleHistory) && !IsInProgress(objScheduleHistory) && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && objScheduleHistory.IsEnable) { objScheduleHistory.Status = null; AddToScheduleQueue(objScheduleHistory); } } DateTime lastQueueRefresh = DateTime.Now; bool refreshQueueSchedule = false; while (FreeThreads > 0 && KeepRunning && !ForceReloadSchedule) { if (GetScheduleQueueCount() > 0) { FireEvents(true); } if (KeepThreadAlive == false) { return; } if (_writerTimeouts > 20 || _readerTimeouts > 20) { if (KeepRunning) { Thread.Sleep(TimeSpan.FromMinutes(10)); } else { return; } } else { if (KeepRunning) { Thread.Sleep(TimeSpan.FromSeconds(10)); } else { return; } if ((lastQueueRefresh.AddMinutes(10) <= DateTime.Now || ForceReloadSchedule) && FreeThreads == _maxThreadCount) { refreshQueueSchedule = true; break; } } } if (KeepRunning) { if (refreshQueueSchedule == false) { SetScheduleStatus(ScheduleStatus.WAITING_FOR_OPEN_THREAD); // Thread.Sleep(10000); //sleep for 10 seconds } } else { return; } } catch (Exception exc) { ErrorLogger.SchedulerProcessException(exc); //sleep for 10 minutes //Thread.Sleep(600000); } } } finally { SetScheduleStatus(ScheduleStatus.STOPPED); KeepRunning = false; ActiveThreadCount = 0; } }
public static int AddTaskHistory(ScheduleHistory scheduleHistory) { int id = 0; List<KeyValuePair<string, object>> ParameterCollection = new List<KeyValuePair<string, object>>(); ParameterCollection.Add(new KeyValuePair<string, object>("@ScheduleID", scheduleHistory.ScheduleID)); ParameterCollection.Add(new KeyValuePair<string, object>("@StartDate", scheduleHistory.HistoryStartDate)); ParameterCollection.Add(new KeyValuePair<string, object>("@EndDate", scheduleHistory.HistoryEndDate)); ParameterCollection.Add(new KeyValuePair<string, object>("@Status", scheduleHistory.Status)); ParameterCollection.Add(new KeyValuePair<string, object>("@NextStart", scheduleHistory.NextStart)); ParameterCollection.Add(new KeyValuePair<string, object>("@Server", scheduleHistory.Server)); try { id = sagesql.ExecuteNonQuery("usp_ScheduleHistoryAdd", ParameterCollection, "@id"); } catch (Exception) { throw; } return id; }
public void Run(ScheduleHistory objScheduleHistory) { TaskBase Process = null; try { //This is called from RunPooledThread() ticksElapsed = Environment.TickCount - ticksElapsed; Process = GetTaskBase(objScheduleHistory.FullNamespace, objScheduleHistory); Process.TaskRecordItem = objScheduleHistory; //Set up the handlers for the CoreScheduler Process.ScheduleStarted += Scheduler.TaskStarted; // Process.ScheduleProcessing += Scheduler.CoreScheduler.WorkProgressing; Process.ScheduleCompleted += Scheduler.TaskCompleted; Process.ScheduleErrored += Scheduler.TaskErrored; //This kicks off the DoWork method of the class //type specified in the configuration. Process.Started(); try { Process.TaskRecordItem.Status = false; Process.Execute(); } catch (Exception exc) { //in case the scheduler client //didn't have proper exception handling //make sure we fire the Errored event if (Process != null) { if (Process.TaskRecordItem != null) { Process.TaskRecordItem.Status = false; } Process.Error(ref exc); } } if (Process.TaskRecordItem.Status == true) { Process.Completed(); } //If all processes in this ProcessGroup have //completed, set the ticksElapsed and raise //the Completed event. //I don't think this is necessary with the //other events. I'll leave it for now and //will probably take it out later. if (processesCompleted == numberOfProcesses) { if (processesCompleted == numberOfProcesses) { ticksElapsed = Environment.TickCount - ticksElapsed; if (Completed != null) { Completed(); } } } } catch (Exception exc) { //in case the scheduler client //didn't have proper exception handling //make sure we fire the Errored event if (Process != null) { if (Process.TaskRecordItem != null) { Process.TaskRecordItem.Status = false; } Process.Error(ref exc); } } finally { //Track how many processes have completed for //this instanciation of the ProcessGroup numberOfProcessesInQueue -= 1; processesCompleted += 1; if (Process != null) { try { Process.Completed(); ((IDisposable)Process).Dispose(); Process = null; } catch (Exception) { Process.Completed(); Process = null; } } } }
public void Run(ScheduleHistory objScheduleHistory) { TaskBase Process = null; try { //This is called from RunPooledThread() ticksElapsed = Environment.TickCount - ticksElapsed; Process = GetTaskBase(objScheduleHistory.FullNamespace, objScheduleHistory); Process.TaskRecordItem = objScheduleHistory; //Set up the handlers for the CoreScheduler Process.ScheduleStarted += Scheduler.TaskStarted; // Process.ScheduleProcessing += Scheduler.CoreScheduler.WorkProgressing; Process.ScheduleCompleted += Scheduler.TaskCompleted; Process.ScheduleErrored += Scheduler.TaskErrored; //This kicks off the DoWork method of the class //type specified in the configuration. Process.Started(); try { Process.TaskRecordItem.Status = false; Process.Execute(); } catch (Exception exc) { //in case the scheduler client //didn't have proper exception handling //make sure we fire the Errored event if (Process != null) { if (Process.TaskRecordItem != null) { Process.TaskRecordItem.Status = false; } Process.Error(ref exc); } } if (Process.TaskRecordItem.Status ==true) { Process.Completed(); } //If all processes in this ProcessGroup have //completed, set the ticksElapsed and raise //the Completed event. //I don't think this is necessary with the //other events. I'll leave it for now and //will probably take it out later. if (processesCompleted == numberOfProcesses) { if (processesCompleted == numberOfProcesses) { ticksElapsed = Environment.TickCount - ticksElapsed; if (Completed != null) { Completed(); } } } } catch (Exception exc) { //in case the scheduler client //didn't have proper exception handling //make sure we fire the Errored event if (Process != null) { if (Process.TaskRecordItem != null) { Process.TaskRecordItem.Status= false; } Process.Error(ref exc); } } finally { //Track how many processes have completed for //this instanciation of the ProcessGroup numberOfProcessesInQueue -= 1; processesCompleted += 1; } }
private TaskBase GetTaskBase(string strProcess, ScheduleHistory objScheduleHistory) { //This is a method to encapsulate returning //an object whose class inherits TaskBase. Type t = BuildManager.GetType(strProcess, true, true); var param = new ScheduleHistory[1]; param[0] = objScheduleHistory; var types = new Type[1]; //Get the constructor for the Class types[0] = typeof(ScheduleHistory); System.Reflection.ConstructorInfo objConstructor; objConstructor = t.GetConstructor(types); TaskBase taskBase = null; if (objConstructor != null) { taskBase = (TaskBase)objConstructor.Invoke(param); } return taskBase; }