Exemple #1
0
        public void StartAllIStartable()
        {
            HealthChecks.RegisterHealthCheck("Startable", (Func <HealthCheckResult>)StartableHealtCheck);
            IHandler[] handlers = Kernel.GetAssignableHandlers(typeof(object));
            IEnumerable <HandlerInfo> startableHandlers = GetStartableHandlers(handlers);

            foreach (var handlerInfo in startableHandlers.OrderBy(h => h.Priority))
            {
                try
                {
                    handlerInfo.Handler.Resolve(CreationContext.CreateEmpty());
                    _logger.InfoFormat("Component {0} started correctly.", handlerInfo.Description);
                }
                catch (Exception ex)
                {
                    _logger.ErrorFormat(ex, "Cannot start component {0} because it raised exception. Retry in {1} seconds.", handlerInfo.Description, _timeoutInSecondsBeforeRetryRestartFailedServices);
                    handlerInfo.StartException = ex;
                    _handlersWithStartError.Add(handlerInfo);
                }
            }
            if (_handlersWithStartError.Count > 0)
            {
                _retryStartTimer = new System.Threading.Timer(
                    RetryStartTimerCallback,
                    null,
                    1000 * _timeoutInSecondsBeforeRetryRestartFailedServices, //Due time
                    1000 * _timeoutInSecondsBeforeRetryRestartFailedServices  //Period
                    );
            }
        }
Exemple #2
0
        public static void Register(HttpConfiguration config, IQuery store, IEnumerable <IHealthCheck> healthChecks = null)
        {
            HealthChecks.SetSiteName(HostingEnvironment.SiteName);
            HealthChecks.SetApplication(ConfigurationManager.AppSettings["ASI:ApplicationName"] ?? HostingEnvironment.ApplicationVirtualPath);
            var checks = healthChecks as IHealthCheck[] ?? healthChecks?.ToArray() ?? new IHealthCheck[] { };

            if (checks.OfType <PerformanceHealthCheck>().Any())
            {
                HealthChecks.RegisterHealthCheck(new PerformanceHealthCheck("Performance", store));
            }

            for (var i = 0; i < ConfigurationManager.ConnectionStrings.Count; i++)
            {
                HealthChecks.RegisterHealthCheck(new DatabaseConnectivityHealthCheck(ConfigurationManager.ConnectionStrings[i]));
            }

            if (healthChecks != null)
            {
                foreach (var check in checks)
                {
                    HealthChecks.RegisterHealthCheck(check);
                }
            }

            var interval = GetPollingInterval();

            HealthChecks.Poll((int)TimeSpan.FromMinutes(interval).TotalMilliseconds);
        }
        protected override void OnStart(string[] args)
        {
            Log.Debug("OnStart");
            if (HealthChecksSection == null || HealthChecksSection.HealthChecks == null || HealthChecksSection.HealthChecks.Count == 0)
            {
                Log.Error(SystemConstants.MISSING_HEALTH_CHECK_SECTION);
            }

            try
            {
                HealthChecks healthCheckConfigs = HealthChecksSection.GetConfig().HealthChecks;
                for (int ii = 0; ii < healthCheckConfigs.Count; ii++)
                {
                    healthChecks.Add(healthCheckConfigs[ii]);
                }

                IKernel kernel = new BindKernelwithHealthChecks(new StandardKernel(new ServiceModule()), HealthChecksSection.HealthChecks).Bind();
                healthCheckList = new HealthCheckList(healthChecks, kernel);
                healthCheckList.HealthCheckError += HealthCheckList_HealthCheckError;
                healthCheckList.SeriousResult    += HealthCheckList_SeriousResult;
                healthCheckList.Start();
            }
            catch (ScheduleProviderException ex)
            {
                Log.ErrorFormat($"Failed: {ex.ProviderName}");
                Log.Error(ex);
                OnStop();
            }
            finally
            {
                Log.Debug("Finished OnStart");
            }
        }
 public BindKernelwithHealthChecks(StandardKernel kernel, HealthChecks healthChecks)
 {
     if (kernel == null || healthChecks == null)
     {
         throw new ArgumentNullException("kernel or HealthChecks parameter is null");
     }
     Kernel       = kernel;
     HealthChecks = healthChecks;
 }