AspNetCore.Diagnostics.HealthChecks
AspNetCore.Diagnostics.HealthChecks copied to clipboard
Is there a way to restrict when the Health Checks run?
What would you like to be added: I want to only run these HealthChecks around business hours. So ideally, given the specific HealthCheck information and current time, I want to be able to specify whether the HealthCheck collector will run. This would in conjunction with "SetEvaluationTimeInSeconds".
This was mentioned in a previous issue #459, but no action was taken.
Why is this needed: I need this to run at only specific times because the healthchecks cause pinged sites to stay up forever without hibernating. I am currently pinging sites on IIS and they will never go to sleep with the healthcheck pinging so frequently.
Example Setup Code
services
.AddHealthChecksUI(setupSettings: setup =>
{
setup.ShouldExecuteHealthChecksCollectorCallback
(serviceProvider=> DateTime.UtcNow.Hour >= 8 && DateTime.UtcNow.Hour < 20);
});
Or... another dummy sample:
services
.AddHealthChecksUI(setupSettings: setup =>
{
setup.ShouldExecuteHealthChecksCollectorCallback(serviceProvider=> {
var scheduler = serviceProvider.GetRequiredService<IHealthExecutorScheduler>();
return scheduler.ShouldExecute();
});
PR is welcome.