/// <summary> /// The run. /// </summary> public override void Run() { Log.Info(EventCode.DealsEmailingEntryPoint, "User Services worker role entry point"); try { MailingManager mailingManager = new MailingManager(); var jobProcessors = mailingManager.Bootstrap(RoleEnvironment.CurrentRoleInstance.Id); foreach (EmailJobProcessor jobProcessor in jobProcessors) { EmailJobProcessor emailJobProcessor = jobProcessor; Task.Factory.StartNew(() => emailJobProcessor.DoWork(null)) .ContinueWith(task => Log.Critical(EventCode.DealsEmailingUnexpectedError, task.Exception, "Unexpected Error From Agent"), TaskContinuationOptions.OnlyOnFaulted); } //Start the Email job fetcher JobFetcher.Start(); ReportingManager reportingManager = new ReportingManager(); var transactionJobProcessors = reportingManager.Bootstrap(RoleEnvironment.CurrentRoleInstance.Id); foreach (TransactionJobProcessor jobProcessor in transactionJobProcessors) { TransactionJobProcessor transactionJobProcessor = jobProcessor; Task.Factory.StartNew(() => transactionJobProcessor.DoWork(null)) .ContinueWith(task => Log.Critical(EventCode.DealsEmailingUnexpectedError, task.Exception, "Unexpected Error From Agent"), TaskContinuationOptions.OnlyOnFaulted); } } catch (Exception exception) { Log.Critical(EventCode.DealsEmailingInitializeError, exception, "Couldn't initialize user services worker role"); // Sleep in order to make sure that the exception is being written to the logs Thread.Sleep(TimeSpan.FromSeconds(60)); throw; } // Initalize complete - keep the role alive while (true) { Thread.Sleep(10000); Log.Verbose("User Services worker role running"); } }