34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
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;
|
|
}
|
|
} |