Open
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Currently there is no way to run health checks like DbContextCheck periodically. Therefor the Health check endpoints can be abused to be very exhaustive for the API.
Describe the solution you'd like
There are already HealthCheckPublishers but currently even when they are applied the checks are made on each request. It would be nice if there was an option to use this also for returning the last published check results. It would be even better to be able to cache the results without an additional publisher by just using an additional setting or allowing to hook into the process to add a cache.
Additional context
public class PeriodHealthCheckPublisher : IHealthCheckPublisher
{
public Task PublishAsync(HealthReport report, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
services.Configure<HealthCheckPublisherOptions>(options =>
{
options.Delay = TimeSpan.FromSeconds(2); // Initial delay
options.Period = TimeSpan.FromSeconds(60); // delay between checks
options.Predicate = _ => true;
});
services.AddSingleton<IHealthCheckPublisher, PeriodHealthCheckPublisher>();
services.AddHealthChecks();
Currently whenever the healthcheck endpoint is called all the checks are executed again.