Example #1
0
        public void Started()
        {
            WorkStarted workStarted1 = this.ProcessStartedEvent;

            if (workStarted1 == null)
            {
                return;
            }
            SchedulerClient schedulerClient = this;

            workStarted1(ref schedulerClient);
        }
Example #2
0
        public void Errored(ref Exception objException)
        {
            WorkErrored workErrored = this.ProcessErroredEvent;

            if (workErrored == null)
            {
                return;
            }
            SchedulerClient schedulerClient = this;

            workErrored(ref schedulerClient, ref objException);
        }
Example #3
0
        public void Progressing()
        {
            WorkProgressing workProgressing = this.ProcessProgressingEvent;

            if (workProgressing == null)
            {
                return;
            }
            SchedulerClient schedulerClient = this;

            workProgressing(ref schedulerClient);
        }
Example #4
0
        public void Completed()
        {
            WorkCompleted workCompleted = this.ProcessCompletedEvent;

            if (workCompleted == null)
            {
                return;
            }
            SchedulerClient schedulerClient = this;

            workCompleted(ref schedulerClient);
        }
Example #5
0
        public void Run(ScheduleHistoryItem objScheduleHistoryItem)
        {
            SchedulerClient Process = null;

            try
            {
                //This is called from RunPooledThread()
                ticksElapsed = Environment.TickCount - ticksElapsed;
                Process      = GetSchedulerClient(objScheduleHistoryItem.TypeFullName, objScheduleHistoryItem);
                Process.ScheduleHistoryItem = objScheduleHistoryItem;

                //Set up the handlers for the CoreScheduler
                Process.ProcessStarted     += Scheduler.CoreScheduler.WorkStarted;
                Process.ProcessProgressing += Scheduler.CoreScheduler.WorkProgressing;
                Process.ProcessCompleted   += Scheduler.CoreScheduler.WorkCompleted;
                Process.ProcessErrored     += Scheduler.CoreScheduler.WorkErrored;
                //This kicks off the DoWork method of the class
                //type specified in the configuration.

                Process.Started();
                try
                {
                    Process.ScheduleHistoryItem.Succeeded = false;
                    Process.DoWork();
                }
                catch (Exception exc)
                {
                    //in case the scheduler client
                    //didn't have proper exception handling
                    //make sure we fire the Errored event
                    Logger.Error(exc);

                    if (Process != null)
                    {
                        if (Process.ScheduleHistoryItem != null)
                        {
                            Process.ScheduleHistoryItem.Succeeded = false;
                        }
                        Process.Errored(ref exc);
                    }
                }
                if (Process.ScheduleHistoryItem.Succeeded)
                {
                    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.ScheduleHistoryItem != null)
                    {
                        Process.ScheduleHistoryItem.Succeeded = false;
                    }
                    Process.Errored(ref exc);
                }
                else
                {
                    //when the schedule has invalid config and can't initialize the Process,
                    //we need also trigger work errored event so that the schedule can remove from inprogress and inqueue list to prevent endless loop.
                    Scheduler.CoreScheduler.WorkStarted(objScheduleHistoryItem);
                    objScheduleHistoryItem.Succeeded = false;
                    Scheduler.CoreScheduler.WorkErrored(objScheduleHistoryItem, exc);
                }
            }
            finally
            {
                //Track how many processes have completed for
                //this instanciation of the ProcessGroup
                numberOfProcessesInQueue -= 1;
                processesCompleted       += 1;
            }
        }
 public static void WorkStarted(SchedulerClient schedulerClient)
 {
     WorkStarted(schedulerClient.ScheduleHistoryItem);
 }
 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);
     }
 }
 public static void WorkErrored(SchedulerClient schedulerClient, Exception exception)
 {
     WorkErrored(schedulerClient.ScheduleHistoryItem, exception);
 }
            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);
                }
            }
Example #10
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);
                }
            }
Example #11
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);
                }
            }