Project
This commit is contained in:
34
HealtRegistry/Services/HealthService.cs
Normal file
34
HealtRegistry/Services/HealthService.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using HealtRegistry.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace HealtRegistry.Services;
|
||||
|
||||
public class HealthService : IHealthService
|
||||
{
|
||||
|
||||
public Dictionary<string, ServiceHealthData> ServiceHealthes { get; } = new();
|
||||
|
||||
public HealthService(IOptions<ServicesConfiguration> servicesConfiguration)
|
||||
{
|
||||
foreach (var service in servicesConfiguration.Value.Services)
|
||||
{
|
||||
ServiceHealthes.Add(service.Key, new ServiceHealthData()
|
||||
{
|
||||
Healthy = service.Value.DefaultValue,
|
||||
LastUpdated = DateTimeOffset.Now
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceHealthes GetServiceHealthes()
|
||||
{
|
||||
var serviceHealthes = ServiceHealthes.ToDictionary(x => x.Key, x => new ServiceHealth(x.Value.Healthy));
|
||||
return new ServiceHealthes(serviceHealthes);
|
||||
}
|
||||
|
||||
public void SetServiceHealth(string serviceName, bool health)
|
||||
{
|
||||
ServiceHealthes[serviceName].Healthy = health;
|
||||
ServiceHealthes[serviceName].LastUpdated = DateTimeOffset.Now;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user