/// <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 static TimeSpan GetNotificationDelay(this HealthChecksSettings settings, ICronTabParser cronTabParser, DateTime now, TimeSpan defaultDelay) { // If first run time not set, start with just small delay after application start. var firstRunTime = settings.Notification.FirstRunTime; if (string.IsNullOrEmpty(firstRunTime)) { return(defaultDelay); } // Otherwise start at scheduled time according to cron expression, unless within the default delay period. DateTime firstRunOccurance = cronTabParser.GetNextOccurrence(firstRunTime, now); TimeSpan delay = firstRunOccurance - now; return(delay < defaultDelay ? defaultDelay : delay); }
/// <summary> /// Initializes a new instance of the <see cref="HealthChecksSettingsValidator" /> class. /// </summary> /// <param name="cronTabParser">Helper for parsing crontab expressions.</param> public HealthChecksSettingsValidator(ICronTabParser cronTabParser) => _cronTabParser = cronTabParser;