コード例 #1
0
        public override bool OnStart()
        {
            try
            {
                // Set the maximum number of concurrent connections
                ServicePointManager.DefaultConnectionLimit = 12;

                RoleStartupHelper.StartDiagnostics();
                InitializeBlockStorage();
                StartBlockUpdateService();
                StartStoreWorkerService();
                StoreConfiguration.DefaultStoreConfiguration.StoreManagerType = typeof(AzureStoreManager);
                var jobQueueConnectionString = RoleEnvironment.GetConfigurationSettingValue("ManagementDatabaseConnectionString");
                Trace.TraceInformation("Initializing SQL job queue");
                _jobQueue = new SqlJobQueue(jobQueueConnectionString, RoleEnvironment.CurrentRoleInstance.Id);
                Trace.TraceInformation("Job queue initialized");
                EventLog.WriteEntry("AzureEventLogs",
                                    "Worker role started",
                                    EventLogEntryType.Information);
                return(base.OnStart());
            }
            catch (Exception ex)
            {
                Trace.TraceError("WorkerRole OnStart failed: " + ex);
                EventLog.WriteEntry("AzureEventLogs",
                                    "OnStart failed for StoreWorker role: Exception:" + ex.GetType().FullName +
                                    ", Message:" + ex.Message,
                                    EventLogEntryType.Error, 0);
                Trace.TraceError("Sleeping for long enough to allow errors to flush");
                Thread.Sleep(TimeSpan.FromMinutes(1.5));
                Trace.TraceError("Aborting role startup");
                return(false);
            }
        }
コード例 #2
0
 public override bool OnStart()
 {
     try
     {
         base.OnStart();
         _monitorPeriod = TimeSpan.FromMinutes(BasePeriod * RoleEnvironment.CurrentRoleInstance.Role.Instances.Count);
         var rnd   = new Random();
         var start = rnd.Next((int)_monitorPeriod.TotalMinutes);
         // Randomize time to first invocation to prevent all gateways from synchronizing on the same time
         _monitorTimer = new Timer(MonitorCallback, null, TimeSpan.FromMinutes(start), _monitorPeriod);
         RoleStartupHelper.StartDiagnostics();
         return(true);
     }
     catch (Exception ex)
     {
         Trace.TraceError("Gateway WebRole OnStart failed: " + ex);
         EventLog.WriteEntry("AzureEventLogs",
                             "OnStart failed for Gateway role: Exception:" + ex.GetType().FullName +
                             ", Message:" + ex.Message,
                             EventLogEntryType.Error, 0);
         Trace.TraceError("Sleeping for long enough to allow errors to flush");
         Thread.Sleep(TimeSpan.FromMinutes(1.5));
         Trace.TraceError("Aborting role startup");
         return(false);
     }
 }