/// <summary> /// Initializes a new instance of the <see cref="HealthCheckNotifier"/> class. /// </summary> /// <param name="healthChecksSettings">The configuration for health check settings.</param> /// <param name="healthChecks">The collection of healthchecks.</param> /// <param name="notifications">The collection of healthcheck notification methods.</param> /// <param name="runtimeState">Representation of the state of the Umbraco runtime.</param> /// <param name="serverRegistrar">Provider of server registrations to the distributed cache.</param> /// <param name="mainDom">Representation of the main application domain.</param> /// <param name="scopeProvider">Provides scopes for database operations.</param> /// <param name="logger">The typed logger.</param> /// <param name="profilingLogger">The profiling logger.</param> /// <param name="cronTabParser">Parser of crontab expressions.</param> public HealthCheckNotifier( IOptionsMonitor <HealthChecksSettings> healthChecksSettings, HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications, IRuntimeState runtimeState, IServerRoleAccessor serverRegistrar, IMainDom mainDom, ICoreScopeProvider scopeProvider, ILogger <HealthCheckNotifier> logger, IProfilingLogger profilingLogger, ICronTabParser cronTabParser) : base( logger, healthChecksSettings.CurrentValue.Notification.Period, healthChecksSettings.CurrentValue.GetNotificationDelay(cronTabParser, DateTime.Now, DefaultDelay)) { _healthChecksSettings = healthChecksSettings.CurrentValue; _healthChecks = healthChecks; _notifications = notifications; _runtimeState = runtimeState; _serverRegistrar = serverRegistrar; _mainDom = mainDom; _scopeProvider = scopeProvider; _logger = logger; _profilingLogger = profilingLogger; healthChecksSettings.OnChange(x => { _healthChecksSettings = x; ChangePeriod(x.Notification.Period); }); }
public HealthCheckNotifier(IBackgroundTaskRunner <RecurringTaskBase> runner, int delayMilliseconds, int periodMilliseconds, HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications, IRuntimeState runtimeState, IProfilingLogger logger) : base(runner, delayMilliseconds, periodMilliseconds) { _healthChecks = healthChecks; _notifications = notifications; _runtimeState = runtimeState; _logger = logger; }
public SchedulerComponent(IRuntimeState runtime, IContentService contentService, IAuditService auditService, HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications, IScopeProvider scopeProvider, IProfilingLogger logger) { _runtime = runtime; _contentService = contentService; _auditService = auditService; _scopeProvider = scopeProvider; _logger = logger; _healthChecks = healthChecks; _notifications = notifications; }
private HealthCheckNotifier CreateHealthCheckNotifier( bool enabled = true, RuntimeLevel runtimeLevel = RuntimeLevel.Run, ServerRole serverRole = ServerRole.Single, bool isMainDom = true, bool notificationEnabled = true) { var settings = new HealthChecksSettings { Notification = new HealthChecksNotificationSettings { Enabled = enabled, DisabledChecks = new List <DisabledHealthCheckSettings> { new DisabledHealthCheckSettings { Id = Guid.Parse(Check3Id) } } }, DisabledChecks = new List <DisabledHealthCheckSettings> { new DisabledHealthCheckSettings { Id = Guid.Parse(Check2Id) } } }; var checks = new HealthCheckCollection(() => new List <HealthCheck> { new TestHealthCheck1(), new TestHealthCheck2(), new TestHealthCheck3(), }); _mockNotificationMethod = new Mock <IHealthCheckNotificationMethod>(); _mockNotificationMethod.SetupGet(x => x.Enabled).Returns(notificationEnabled); var notifications = new HealthCheckNotificationMethodCollection(() => new List <IHealthCheckNotificationMethod> { _mockNotificationMethod.Object }); var mockRunTimeState = new Mock <IRuntimeState>(); mockRunTimeState.SetupGet(x => x.Level).Returns(runtimeLevel); var mockServerRegistrar = new Mock <IServerRoleAccessor>(); mockServerRegistrar.Setup(x => x.CurrentServerRole).Returns(serverRole); var mockMainDom = new Mock <IMainDom>(); mockMainDom.SetupGet(x => x.IsMainDom).Returns(isMainDom); var mockScopeProvider = new Mock <IScopeProvider>(); var mockLogger = new Mock <ILogger <HealthCheckNotifier> >(); var mockProfilingLogger = new Mock <IProfilingLogger>(); return(new HealthCheckNotifier( Options.Create(settings), checks, notifications, mockRunTimeState.Object, mockServerRegistrar.Object, mockMainDom.Object, mockScopeProvider.Object, mockLogger.Object, mockProfilingLogger.Object, Mock.Of <ICronTabParser>())); }
private IBackgroundTask RegisterHealthCheckNotifier(IHealthChecks healthCheckConfig, HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications, IProfilingLogger logger) { // If first run time not set, start with just small delay after application start int delayInMilliseconds; if (string.IsNullOrEmpty(healthCheckConfig.NotificationSettings.FirstRunTime)) { delayInMilliseconds = DefaultDelayMilliseconds; } else { // Otherwise start at scheduled time delayInMilliseconds = DateTime.Now.PeriodicMinutesFrom(healthCheckConfig.NotificationSettings.FirstRunTime) * 60 * 1000; if (delayInMilliseconds < DefaultDelayMilliseconds) { delayInMilliseconds = DefaultDelayMilliseconds; } } var periodInMilliseconds = healthCheckConfig.NotificationSettings.PeriodInHours * 60 * 60 * 1000; var task = new HealthCheckNotifier(_healthCheckRunner, delayInMilliseconds, periodInMilliseconds, healthChecks, notifications, _scopeProvider, _runtime, logger); _healthCheckRunner.TryAdd(task); return(task); }