// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; namespace Microsoft.Extensions.Diagnostics.HealthChecks { /// /// Options for the default service that executes instances. /// public sealed class HealthCheckPublisherOptions { private TimeSpan _delay; private TimeSpan _period; public HealthCheckPublisherOptions() { _delay = TimeSpan.FromSeconds(5); _period = TimeSpan.FromSeconds(30); } /// /// Gets or sets the initial delay applied after the application starts before executing /// instances. The delay is applied once at startup, and does /// not apply to subsequent iterations. The default value is 5 seconds. /// public TimeSpan Delay { get => _delay; set { if (value == System.Threading.Timeout.InfiniteTimeSpan) { throw new ArgumentException($"The {nameof(Delay)} must not be infinite.", nameof(value)); } _delay = value; } } /// /// Gets or sets the period of execution. The default value is /// 30 seconds. /// /// /// The cannot be set to a value lower than 1 second. /// public TimeSpan Period { get => _period; set { if (value < TimeSpan.FromSeconds(1)) { throw new ArgumentException($"The {nameof(Period)} must be greater than or equal to one second.", nameof(value)); } if (value == System.Threading.Timeout.InfiniteTimeSpan) { throw new ArgumentException($"The {nameof(Period)} must not be infinite.", nameof(value)); } _delay = value; } } /// /// Gets or sets a predicate that is used to filter the set of health checks executed. /// /// /// If is null, the health check publisher service will run all /// registered health checks - this is the default behavior. To run a subset of health checks, /// provide a function that filters the set of checks. The predicate will be evaluated each period. /// public Func Predicate { get; set; } /// /// Gets or sets the timeout for executing the health checks an all /// instances. Use to execute with no timeout. /// The default value is 30 seconds. /// public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(30); } }