Пример #1
0
 public static void WorkProgressing(SchedulerClient schedulerClient)
 {
     try
     {
         //A SchedulerClient is notifying us that their
         //process is in progress.  Informational only.
         if (schedulerClient.ScheduleHistoryItem.RetainHistoryNum > 0)
         {
             //Write out the log entry for this event
             var log = new LogInfo {LogTypeKey = "SCHEDULER_EVENT_PROGRESSING"};
             log.AddProperty("THREAD ID", Thread.CurrentThread.GetHashCode().ToString());
             log.AddProperty("TYPE", schedulerClient.GetType().FullName);
             log.AddProperty("SOURCE", schedulerClient.ScheduleHistoryItem.ScheduleSource.ToString());
             log.AddProperty("ACTIVE THREADS", _activeThreadCount.ToString());
             log.AddProperty("FREE THREADS", FreeThreads.ToString());
             log.AddProperty("READER TIMEOUTS", _readerTimeouts.ToString());
             log.AddProperty("WRITER TIMEOUTS", _writerTimeouts.ToString());
             log.AddProperty("IN PROGRESS", GetScheduleInProgressCount().ToString());
             log.AddProperty("IN QUEUE", GetScheduleQueueCount().ToString());
             LogController.Instance.AddLog(log);
         }
     }
     catch (Exception exc)
     {
         Exceptions.Exceptions.ProcessSchedulerException(exc);
     }
 }
Пример #2
0
            public static void WorkStarted(SchedulerClient schedulerClient)
            {
                bool activeThreadCountIncremented = false;
                try
                {
                    schedulerClient.ScheduleHistoryItem.ThreadID = Thread.CurrentThread.GetHashCode();

                    //Put the object in the ScheduleInProgress collection
                    //and remove it from the ScheduleQueue
                    RemoveFromScheduleQueue(schedulerClient.ScheduleHistoryItem);
                    AddToScheduleInProgress(schedulerClient.ScheduleHistoryItem);

                    //A SchedulerClient is notifying us that their
                    //process has started.  Increase our ActiveThreadCount
                    Interlocked.Increment(ref _activeThreadCount);
                    activeThreadCountIncremented = true;

                    //Update the schedule item
                    //object property to note the start time.
                    schedulerClient.ScheduleHistoryItem.StartDate = DateTime.Now;
                    AddScheduleHistory(schedulerClient.ScheduleHistoryItem);


                    if (schedulerClient.ScheduleHistoryItem.RetainHistoryNum > 0)
                    {
                        //Write out the log entry for this event
                        var eventLogController = new EventLogController();
                        var eventLogInfo = new LogInfo();
                        eventLogInfo.AddProperty("THREAD ID", Thread.CurrentThread.GetHashCode().ToString());
                        eventLogInfo.AddProperty("TYPE", schedulerClient.GetType().FullName);
                        eventLogInfo.AddProperty("SOURCE", schedulerClient.ScheduleHistoryItem.ScheduleSource.ToString());
                        eventLogInfo.AddProperty("ACTIVE THREADS", _activeThreadCount.ToString());
                        eventLogInfo.AddProperty("FREE THREADS", FreeThreads.ToString());
                        eventLogInfo.AddProperty("READER TIMEOUTS", _readerTimeouts.ToString());
                        eventLogInfo.AddProperty("WRITER TIMEOUTS", _writerTimeouts.ToString());
                        eventLogInfo.AddProperty("IN PROGRESS", GetScheduleInProgressCount().ToString());
                        eventLogInfo.AddProperty("IN QUEUE", GetScheduleQueueCount().ToString());
                        eventLogInfo.LogTypeKey = "SCHEDULER_EVENT_STARTED";
                        eventLogController.AddLog(eventLogInfo);
                    }
                }
                catch (Exception exc)
                {
                    //Decrement the ActiveThreadCount because
                    //otherwise the number of active threads
                    //will appear to be climbing when in fact
                    //no tasks are being executed.
                    if (activeThreadCountIncremented)
                    {
                        Interlocked.Decrement(ref _activeThreadCount);
                    }
                    Exceptions.Exceptions.ProcessSchedulerException(exc);
                }
            }
Пример #3
0
            public static void WorkCompleted(SchedulerClient schedulerClient)
            {
                try
                {
                    ScheduleHistoryItem scheduleHistoryItem = schedulerClient.ScheduleHistoryItem;

                    //Remove the object in the ScheduleInProgress collection
                    RemoveFromScheduleInProgress(scheduleHistoryItem);

                    //A SchedulerClient is notifying us that their
                    //process has completed.  Decrease our ActiveThreadCount
                    Interlocked.Decrement(ref _activeThreadCount);

                    //Update the schedule item object property
                    //to note the end time and next start
                    scheduleHistoryItem.EndDate = DateTime.Now;

                    if (scheduleHistoryItem.ScheduleSource == ScheduleSource.STARTED_FROM_EVENT)
                    {
                        scheduleHistoryItem.NextStart = Null.NullDate;
                    }
                    else
                    {
                        if (scheduleHistoryItem.CatchUpEnabled)
                        {
                            switch (scheduleHistoryItem.TimeLapseMeasurement)
                            {
                                case "s":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.NextStart.AddSeconds(scheduleHistoryItem.TimeLapse);
                                    break;
                                case "m":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.NextStart.AddMinutes(scheduleHistoryItem.TimeLapse);
                                    break;
                                case "h":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.NextStart.AddHours(scheduleHistoryItem.TimeLapse);
                                    break;
                                case "d":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.NextStart.AddDays(scheduleHistoryItem.TimeLapse);
                                    break;
                                case "w":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddDays(scheduleHistoryItem.TimeLapse * 7);
                                    break;
                                case "mo":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddMonths(scheduleHistoryItem.TimeLapse);
                                    break;
                                case "y":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddYears(scheduleHistoryItem.TimeLapse);
                                    break;
                            }
                        }
                        else
                        {
                            switch (scheduleHistoryItem.TimeLapseMeasurement)
                            {
                                case "s":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddSeconds(scheduleHistoryItem.TimeLapse);
                                    break;
                                case "m":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddMinutes(scheduleHistoryItem.TimeLapse);
                                    break;
                                case "h":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddHours(scheduleHistoryItem.TimeLapse);
                                    break;
                                case "d":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddDays(scheduleHistoryItem.TimeLapse);
                                    break;
                                case "w":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddDays(scheduleHistoryItem.TimeLapse * 7);
                                    break;
                                case "mo":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddMonths(scheduleHistoryItem.TimeLapse);
                                    break;
                                case "y":
                                    scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddYears(scheduleHistoryItem.TimeLapse);
                                    break;
                            }
                        }
                    }

                    //Update the ScheduleHistory in the database
                    UpdateScheduleHistory(scheduleHistoryItem);

                    if (scheduleHistoryItem.NextStart != Null.NullDate)
                    {
                        //Put the object back into the ScheduleQueue
                        //collection with the new NextStart date.
                        scheduleHistoryItem.StartDate = Null.NullDate;
                        scheduleHistoryItem.EndDate = Null.NullDate;
                        scheduleHistoryItem.LogNotes = "";
                        scheduleHistoryItem.ProcessGroup = -1;
                        AddToScheduleQueue(scheduleHistoryItem);
                    }


                    if (schedulerClient.ScheduleHistoryItem.RetainHistoryNum > 0)
                    {
                        var log = new LogInfo {LogTypeKey = "SCHEDULER_EVENT_COMPLETED"};
                        log.AddProperty("TYPE", schedulerClient.GetType().FullName);
                        log.AddProperty("THREAD ID", Thread.CurrentThread.GetHashCode().ToString());
                        log.AddProperty("NEXT START", Convert.ToString(scheduleHistoryItem.NextStart));
                        log.AddProperty("SOURCE", schedulerClient.ScheduleHistoryItem.ScheduleSource.ToString());
                        log.AddProperty("ACTIVE THREADS", _activeThreadCount.ToString());
                        log.AddProperty("FREE THREADS", FreeThreads.ToString());
                        log.AddProperty("READER TIMEOUTS", _readerTimeouts.ToString());
                        log.AddProperty("WRITER TIMEOUTS", _writerTimeouts.ToString());
                        log.AddProperty("IN PROGRESS", GetScheduleInProgressCount().ToString());
                        log.AddProperty("IN QUEUE", GetScheduleQueueCount().ToString());
                        LogController.Instance.AddLog(log);
                    }
                }
                catch (Exception exc)
                {
                    Exceptions.Exceptions.ProcessSchedulerException(exc);
                }
            }
Пример #4
0
            public static void WorkErrored(SchedulerClient schedulerClient, Exception exception)
            {
                try
                {
                    ScheduleHistoryItem scheduleHistoryItem = schedulerClient.ScheduleHistoryItem;
                    //Remove the object in the ScheduleInProgress collection
                    RemoveFromScheduleInProgress(scheduleHistoryItem);

                    //A SchedulerClient is notifying us that their
                    //process has errored.  Decrease our ActiveThreadCount
                    Interlocked.Decrement(ref _activeThreadCount);


                    Exceptions.Exceptions.ProcessSchedulerException(exception);

                    //Update the schedule item object property
                    //to note the end time and next start
                    scheduleHistoryItem.EndDate = DateTime.Now;
                    if (scheduleHistoryItem.ScheduleSource == ScheduleSource.STARTED_FROM_EVENT)
                    {
                        scheduleHistoryItem.NextStart = Null.NullDate;
                    }
                    else if (scheduleHistoryItem.RetryTimeLapse != Null.NullInteger)
                    {
                        switch (scheduleHistoryItem.RetryTimeLapseMeasurement)
                        {
                            case "s":
                                scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddSeconds(scheduleHistoryItem.RetryTimeLapse);
                                break;
                            case "m":
                                scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddMinutes(scheduleHistoryItem.RetryTimeLapse);
                                break;
                            case "h":
                                scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddHours(scheduleHistoryItem.RetryTimeLapse);
                                break;
                            case "d":
                                scheduleHistoryItem.NextStart = scheduleHistoryItem.StartDate.AddDays(scheduleHistoryItem.RetryTimeLapse);
                                break;
                        }
                    }
                    //Update the ScheduleHistory in the database
                    UpdateScheduleHistory(scheduleHistoryItem);

                    if (scheduleHistoryItem.NextStart != Null.NullDate && scheduleHistoryItem.RetryTimeLapse != Null.NullInteger)
                    {
                        //Put the object back into the ScheduleQueue
                        //collection with the new NextStart date.
                        scheduleHistoryItem.StartDate = Null.NullDate;
                        scheduleHistoryItem.EndDate = Null.NullDate;
                        scheduleHistoryItem.LogNotes = "";
                        scheduleHistoryItem.ProcessGroup = -1;
                        AddToScheduleQueue(scheduleHistoryItem);
                    }

                    if (schedulerClient.ScheduleHistoryItem.RetainHistoryNum > 0)
                    {
                        //Write out the log entry for this event
                        var eventLogController = new EventLogController();
                        var eventLogInfo = new LogInfo();
                        eventLogInfo.AddProperty("THREAD ID", Thread.CurrentThread.GetHashCode().ToString());
                        eventLogInfo.AddProperty("TYPE", schedulerClient.GetType().FullName);
                        if (exception != null)
                        {
                            eventLogInfo.AddProperty("EXCEPTION", exception.Message);
                        }
                        eventLogInfo.AddProperty("RESCHEDULED FOR", Convert.ToString(scheduleHistoryItem.NextStart));
                        eventLogInfo.AddProperty("SOURCE", schedulerClient.ScheduleHistoryItem.ScheduleSource.ToString());
                        eventLogInfo.AddProperty("ACTIVE THREADS", _activeThreadCount.ToString());
                        eventLogInfo.AddProperty("FREE THREADS", FreeThreads.ToString());
                        eventLogInfo.AddProperty("READER TIMEOUTS", _readerTimeouts.ToString());
                        eventLogInfo.AddProperty("WRITER TIMEOUTS", _writerTimeouts.ToString());
                        eventLogInfo.AddProperty("IN PROGRESS", GetScheduleInProgressCount().ToString());
                        eventLogInfo.AddProperty("IN QUEUE", GetScheduleQueueCount().ToString());
                        eventLogInfo.LogTypeKey = "SCHEDULER_EVENT_FAILURE";
                        eventLogController.AddLog(eventLogInfo);
                    }
                }
                catch (Exception exc)
                {
                    Exceptions.Exceptions.ProcessSchedulerException(exc);
                }
            }