7 changed files with 47 additions and 74 deletions
@ -1,33 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.Extensions.Hosting; |
|
||||
|
|
||||
namespace LINGYUN.Abp.MicroService.LocalizationService; |
|
||||
|
|
||||
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; |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,37 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
|
||||
|
namespace LINGYUN.Abp.MicroService.ServiceDefaults; |
||||
|
public static class HealthChecksExtenssions |
||||
|
{ |
||||
|
public static IHostApplicationBuilder AddCustomHealthChecks<THealthCheck>( |
||||
|
this IHostApplicationBuilder builder, |
||||
|
string name, |
||||
|
string tag = "ready") |
||||
|
where THealthCheck : class, IHealthCheck |
||||
|
{ |
||||
|
builder.Services |
||||
|
.AddHealthChecks() |
||||
|
.AddCheck<THealthCheck>(name, tags: [tag]); |
||||
|
|
||||
|
return builder; |
||||
|
} |
||||
|
|
||||
|
public static WebApplication MapCustomHealthChecks( |
||||
|
this WebApplication app, |
||||
|
string pattern, |
||||
|
string tag = "ready") |
||||
|
{ |
||||
|
if (app.Environment.IsDevelopment()) |
||||
|
{ |
||||
|
app.MapHealthChecks(pattern, new HealthCheckOptions |
||||
|
{ |
||||
|
Predicate = r => r.Tags.Contains(tag) |
||||
|
}); |
||||
|
} |
||||
|
return app; |
||||
|
} |
||||
|
} |
||||
@ -1,33 +0,0 @@ |
|||||
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; |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue