diff --git a/sojj/HealthChecks/HealthCheckPublisher.cs b/sojj/HealthChecks/HealthCheckPublisher.cs index f37de41..df9408e 100644 --- a/sojj/HealthChecks/HealthCheckPublisher.cs +++ b/sojj/HealthChecks/HealthCheckPublisher.cs @@ -10,11 +10,15 @@ public class HealthCheckPublisher : IHealthCheckPublisher { private readonly ILogger _logger; private readonly IHttpClientFactory _httpClientFactory; + private readonly string _healthCheckFilePath; - public HealthCheckPublisher(ILogger logger, IHttpClientFactory httpClientFactory) + public HealthCheckPublisher(ILogger logger, IHttpClientFactory httpClientFactory, IConfiguration configuration) { _logger = logger; _httpClientFactory = httpClientFactory; + var healthCheckFilePathString = configuration.GetValue("HealthCheckFilePath") ?? throw new ArgumentNullException("HealthCheckFilePath"); + Directory.CreateDirectory(healthCheckFilePathString); + _healthCheckFilePath = Path.Join(healthCheckFilePathString, Environment.MachineName); } public async Task PublishAsync(HealthReport report, CancellationToken cancellationToken) @@ -29,9 +33,12 @@ public async Task PublishAsync(HealthReport report, CancellationToken cancellati if (report.Status != HealthStatus.Healthy) { + File.Delete(_healthCheckFilePath); return; } + File.Create(_healthCheckFilePath).Dispose(); + var response = await httpClient.GetAsync(string.Empty, cancellationToken); if (response.IsSuccessStatusCode) diff --git a/sojj/appsettings.json b/sojj/appsettings.json index 1f8865b..ff93a49 100644 --- a/sojj/appsettings.json +++ b/sojj/appsettings.json @@ -18,5 +18,6 @@ { "Name": "Console" } ], "Enrich": [ "FromLogContext", "WithMachineName", "FromGlobalLogContext" ] - } + }, + "HealthCheckFilePath": "/healthchecks/", }