You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
33 lines
1.1 KiB
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace LINGYUN.Abp.MicroService.TaskService;
|
|
|
|
internal static class ServiceHealthChecksExtenssions
|
|
{
|
|
private const string HealthEndpointPath = "/service-health";
|
|
private const string DefaultHealthTag = "ready";
|
|
|
|
public static TBuilder AddServiceHealthChecks<TBuilder>(this TBuilder builder, string name = "Service", string tag = DefaultHealthTag) where TBuilder : IHostApplicationBuilder
|
|
{
|
|
builder.Services
|
|
.AddHealthChecks()
|
|
.AddCheck<ServiceHealthCheck>(name, tags: [tag]);
|
|
|
|
return builder;
|
|
}
|
|
|
|
public static WebApplication MapServiceHealthChecks(this WebApplication app, string tag = DefaultHealthTag)
|
|
{
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapHealthChecks(HealthEndpointPath, new HealthCheckOptions
|
|
{
|
|
Predicate = r => r.Tags.Contains(tag)
|
|
});
|
|
}
|
|
return app;
|
|
}
|
|
}
|
|
|