// This method never throws - possible exception already handled inside.
        private bool GenerateMessageSafe()
        {
            bool quitLifeCycle = false;

            try
            {
                State = WorkerState.Busy;
                bool completed = GenerateMessageNetTimed();
                WorkerStatistics.Send();
                if (completed)
                {
                    Tracer.Info("First worker {0} reports completion!", WorkerId);
                    State         = WorkerState.Completed;
                    quitLifeCycle = true;
                }
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
                ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.WorkerStep, ex);
                problemReport.SendProblemReport(ReportPipe);
                quitLifeCycle = true; // Worker which caused unhandled exception should quit rather than try to process more messages
            }
            return(quitLifeCycle);
        }
        public void StartWithWorkerId(string workerId)
        {
            var managerCoreServicesClient = new ManagerCoreServicesClient();
            var managerCoreServicesProxy  = managerCoreServicesClient.ManagerCoreServicesProxy;

            ManagerCoreServicesProxy = managerCoreServicesProxy;
            WorkAssignment           = ManagerCoreServicesProxy.GetWorkAssignment(workerId);

            Init();

            State = WorkerState.Starting;
            try
            {
                BeginWork();
            }
            catch (Exception ex)
            {
                ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.BeginWork, ex);
                problemReport.SendProblemReport(ReportPipe);
                ex.Trace().Swallow();

                Tracer.Debug("WorkerBase: Worker {0} is cleaning and quitting now", WorkerId);
                CleanAndQuit();
                return;
            }
            State = WorkerState.Started;

            RunWorker();

            CleanAndQuit();
        }
        public RoleSlotToken GetFreeSlot()
        {
            try
            {
                PipeMessageEnvelope envelope = HiringPipe.Receive(hiringPipeTimeout);
                if (envelope != null)
                {
                    object message = envelope.Body;
                    RoleSlotToken roleSlot = message as RoleSlotToken;
                    Debug.Assert(null != roleSlot);
                    return roleSlot;
                }

                // Debugging
                //if (SectionName == "S1")
                //{
                //    throw new EVException().AddDbgMsg("Test");
                //}
            }
            catch (Exception ex)
            {
                MessageQueueException messageQueueException = ex as MessageQueueException;
                if (messageQueueException != null && (uint)messageQueueException.ErrorCode == 0x80004005)
                {
                    Tracer.Debug("Cannot find hiring pipe {0}.{1}, so skip processing it.", 
                        WorkRequest.HiringPipeName.SectionName, WorkRequest.PipelineId);
                }
                else
                {
                    ProblemReport problemReport = new ProblemReport(WorkRequest.SectionName, WorkerStage.Unknown, ex);
                    using (Pipe reportPipe = new Pipe(WorkRequest.ReportPipeName))
                    {
                        try
                        {
                            reportPipe.Open();
                            problemReport.SendProblemReport(reportPipe);
                        }
                        catch (Exception innerEx)
                        {
                            innerEx.Trace().Swallow();
                        }
                    }
                }
                throw;
            }
            return null;
        }
Exemple #4
0
        public RoleSlotToken GetFreeSlot()
        {
            try
            {
                PipeMessageEnvelope envelope = HiringPipe.Receive(hiringPipeTimeout);
                if (envelope != null)
                {
                    object        message  = envelope.Body;
                    RoleSlotToken roleSlot = message as RoleSlotToken;
                    Debug.Assert(null != roleSlot);
                    return(roleSlot);
                }

                // Debugging
                //if (SectionName == "S1")
                //{
                //    throw new EVException().AddDbgMsg("Test");
                //}
            }
            catch (Exception ex)
            {
                MessageQueueException messageQueueException = ex as MessageQueueException;
                if (messageQueueException != null && (uint)messageQueueException.ErrorCode == 0x80004005)
                {
                    Tracer.Debug("Cannot find hiring pipe {0}.{1}, so skip processing it.",
                                 WorkRequest.HiringPipeName.SectionName, WorkRequest.PipelineId);
                }
                else
                {
                    ProblemReport problemReport = new ProblemReport(WorkRequest.SectionName, WorkerStage.Unknown, ex);
                    using (Pipe reportPipe = new Pipe(WorkRequest.ReportPipeName))
                    {
                        try
                        {
                            reportPipe.Open();
                            problemReport.SendProblemReport(reportPipe);
                        }
                        catch (Exception innerEx)
                        {
                            innerEx.Trace().Swallow();
                        }
                    }
                }
                throw;
            }
            return(null);
        }
        private void CleanAndQuit()
        {
            State = WorkerState.CleaningUp;
            try
            {
                EndWork();
            }
            catch (Exception ex)
            {
                ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.EndWork, ex);
                problemReport.SendProblemReport(ReportPipe);
                ex.Trace().Swallow();
            }
            State = WorkerState.Quit;

            //Tracer.Trace("Worker {0} reports Quit", WorkerId);
        }
        // This method never throws - possible exception already handled inside.
        private bool ProcessMessageSafe()
        {
            bool quitLifeCycle = false;

            try
            {
#if RECEIVE_WAITS
                PipeMessageEnvelope message = InputDataPipe.Receive(InputDataPipeReceiveTimeout);
#else
                PipeMessageEnvelope message = InputDataPipe.Receive(_zeroWait);
#endif
                if (null != message)
                {
                    State = WorkerState.Busy;
                    SlowDownPostbacks(message);
                    ProcessMessageNoTrans(message);
                }
                else
                {
                    State = WorkerState.Idle;
#if RECEIVE_WAITS
                    WorkerStatistics.RecordIdleTime(InputDataPipeReceiveTimeout);
#else
                    Thread.Sleep(InputDataPipeReceiveTimeout);
#endif
                }
                WorkerStatistics.Send();
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
                ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.WorkerStep, ex);
                problemReport.SendProblemReport(ReportPipe);
                quitLifeCycle = true; // Worker which caused unhandled exception should quit rather than try to process more messages
            }
            return(quitLifeCycle);
        }
        // This method never throws - possible exception already handled inside.
        private bool ProcessMessageSafe()
        {
            bool quitLifeCycle = false;
            try
            {
#if RECEIVE_WAITS
                PipeMessageEnvelope message = InputDataPipe.Receive(InputDataPipeReceiveTimeout);
#else
                PipeMessageEnvelope message = InputDataPipe.Receive(_zeroWait);
#endif
                if (null != message)
                {
                    State = WorkerState.Busy;
                    SlowDownPostbacks(message);
                    ProcessMessageNoTrans(message);
                }
                else
                {
                    State = WorkerState.Idle;
#if RECEIVE_WAITS
                    WorkerStatistics.RecordIdleTime(InputDataPipeReceiveTimeout);
#else
                    Thread.Sleep(InputDataPipeReceiveTimeout);    
#endif
                }
                WorkerStatistics.Send();
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
                ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.WorkerStep, ex);
                problemReport.SendProblemReport(ReportPipe);
                quitLifeCycle = true; // Worker which caused unhandled exception should quit rather than try to process more messages
            }
            return quitLifeCycle;
        }
 // This method never throws - possible exception already handled inside.
 private bool GenerateMessageSafe()
 {
     bool quitLifeCycle = false;
     try
     {
         State = WorkerState.Busy;
         bool completed = GenerateMessageNetTimed();
         WorkerStatistics.Send();
         if (completed)
         {
             Tracer.Info("First worker {0} reports completion!", WorkerId);
             State = WorkerState.Completed;
             quitLifeCycle = true;
         }
     }
     catch (Exception ex)
     {
         ex.Trace().Swallow();
         ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.WorkerStep, ex);
         problemReport.SendProblemReport(ReportPipe);
         quitLifeCycle = true; // Worker which caused unhandled exception should quit rather than try to process more messages
     }
     return quitLifeCycle;
 }
        private void CleanAndQuit()
        {
            State = WorkerState.CleaningUp;
            try
            {
                EndWork();
            }
            catch (Exception ex)
            {
                ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.EndWork, ex);
                problemReport.SendProblemReport(ReportPipe);
                ex.Trace().Swallow();
            }
            State = WorkerState.Quit;

            //Tracer.Trace("Worker {0} reports Quit", WorkerId);
        }
        public void StartWithWorkerId(string workerId)
        {
            var managerCoreServicesClient = new ManagerCoreServicesClient();
            var managerCoreServicesProxy = managerCoreServicesClient.ManagerCoreServicesProxy;
            ManagerCoreServicesProxy = managerCoreServicesProxy;
            WorkAssignment = ManagerCoreServicesProxy.GetWorkAssignment(workerId);

            Init();

            State = WorkerState.Starting;
            try
            {
                BeginWork();
            }
            catch (Exception ex)
            {
                ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.BeginWork, ex);
                problemReport.SendProblemReport(ReportPipe);
                ex.Trace().Swallow();

                Tracer.Debug("WorkerBase: Worker {0} is cleaning and quitting now", WorkerId);
                CleanAndQuit();
                return;
            }
            State = WorkerState.Started;

            RunWorker();

            CleanAndQuit();
        }