Asp.NET Health Checks
public void ConfigureServices(IServiceCollection services)
{
services.AddHealthChecks().AddCheck<ActorSystemHealthCheck>("actor-system");
//...
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//....
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("/health/live");
});
Health Check implementation
public class ActorSystemHealthCheck : IHealthCheck
{
private readonly ActorSystem _system;
public ActorSystemHealthCheck(ActorSystem system)
{
_system = system;
}
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = new CancellationToken()) =>
_system.Shutdown.IsCancellationRequested switch
{
true => Task.FromResult(HealthCheckResult.Unhealthy()),
_ => Task.FromResult(HealthCheckResult.Healthy())
};
}