예제 #1
0
 public void InitializeAgent(Illuminate.Contexts.AgentContext context)
 {
     _context = context;
     LOGNAME = context.LogName;
 }
예제 #2
0
        public void ExecuteJob(string logName, Illuminate.Contexts.AgentContext context)
        {
            LOGNAME = logName;

            Logger.WriteLine("QueueRunner is executing", Logger.Severity.Debug, LOGNAME);

            IQueueEntity queueEntry = Illuminate.ActiveJob.Queue.Instance.GetActiveJobQueueEntryRuntimeNow();

            if (queueEntry != null)
            {
                Illuminate.ActiveJob.Queue.Instance.UpdateAgentId(queueEntry.JobId, queueEntry.Status, "Running", queueEntry.NextRunTime, context.AgentId);

                //get it again to make sure we are the agent registered in the databases
                queueEntry = Illuminate.ActiveJob.Queue.Instance.GetActiveJobQueueEntry(queueEntry.JobId, context.AgentId);
                if (queueEntry != null)
                {
                    //run it
                    Logger.WriteLine("Invoking agent...: " + queueEntry.Name, Logger.Severity.Information, LOGNAME);

                    IAgent job = InvokeJob(queueEntry.DLL);

                    Illuminate.Contexts.AgentContext jobContext = new Illuminate.Contexts.AgentContext(context.NodeId, context.SectionName, LOGNAME, context.Communicator, context.Agent);
                    jobContext.Parameters = queueEntry.Parameters;
                    jobContext.LogName = LOGNAME;

                    if (job != null)
                    {
                        DateTime startTime = DateTime.Now;

                        try
                        {
                            Logger.WriteLine("Starting Job: " + jobContext.AgentId, Logger.Severity.Debug, LOGNAME);

                            Logger.WriteLine("Initialize Job: " + jobContext.AgentId, Logger.Severity.Debug, LOGNAME);
                            job.InitializeAgent(jobContext);

                            Logger.WriteLine("Executing Job: " + jobContext.AgentId, Logger.Severity.Debug, LOGNAME);
                            job.Run();

                            Logger.WriteLine("Cleanup Job: " + jobContext.AgentId, Logger.Severity.Debug, LOGNAME);
                            job.Cleanup();

                        }
                        catch (Illuminate.Exceptions.CriticalException ce)
                        {
                            string body = "There was a critical error running job: " + jobContext.AgentId + ". " + ce.Message + " - " + ce.StackTrace.ToString();

                            //Illuminate.EmailQueue.Queue.Instance.Push(DateTime.Now, "*****@*****.**", "*****@*****.**", "Critical Error on Active Job", body);

                            Logger.WriteLine(body, Logger.Severity.Fatal, LOGNAME);
                        }
                        catch (Illuminate.Exceptions.ErrorException ee)
                        {
                            string body = "There was a serious error running job: " + jobContext.AgentId + ". " + ee.Message + " - " + ee.StackTrace.ToString();

                            //Illuminate.EmailQueue.Queue.Instance.Push(DateTime.Now, "*****@*****.**", "*****@*****.**", "Serious Error on Active Job", body);

                            Logger.WriteLine(body, Logger.Severity.Error, LOGNAME);

                        }
                        catch (Exception e)
                        {
                            string body = "There was a unknown error running job: " + jobContext.AgentId + ". " + e.Message + " - " + e.StackTrace.ToString();

                            //Illuminate.EmailQueue.Queue.Instance.Push(DateTime.Now, "*****@*****.**", "*****@*****.**", "Serious Error on Active Job", body);

                            Logger.WriteLine(body, Logger.Severity.Error, LOGNAME);
                        }
                        finally
                        {
                            DateTime nextRunTime = startTime.AddSeconds(queueEntry.Interval);

                            if (nextRunTime < DateTime.Now) nextRunTime = DateTime.Now;

                            Logger.WriteLine("Resetting next execution time on Job: " + jobContext.AgentId + "Date/Time: " + nextRunTime.ToString(), Logger.Severity.Information, LOGNAME);

                            //process done
                            Illuminate.ActiveJob.Queue.Instance.UpdateAgentId(queueEntry.JobId, "Running", "Idle", nextRunTime, null);
                        }
                    } //End job != null
                    else
                    {
                        Logger.WriteLine("Invoked Agent is NULL...", Logger.Severity.Debug, LOGNAME);

                        //process error
                        Illuminate.ActiveJob.Queue.Instance.UpdateAgentId(queueEntry.JobId, "Running", "Idle", queueEntry.NextRunTime, null);
                    }

                } //Second End QueueEntry != null
            } //First End QueueEntry != null

            CheckExpiredAgent();
        }