コード例 #1
0
ファイル: WorkerRole.cs プロジェクト: BOONRewardsInc/rewards
        /// <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");
            }
        }
コード例 #2
0
ファイル: WorkerRole.cs プロジェクト: BOONRewardsInc/rewards
 /// <summary>
 /// The on stop.
 /// </summary>
 public override void OnStop()
 {
     JobFetcher.Stop();
     Log.Info(EventCode.DealsEmailingStopped, "Deals Emailing Role Stopped");
     base.OnStop();
 }