1 Star 0 Fork 0

IoTSharp / VLPR

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
VLPRHealthCheck.cs 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
麦壳饼 提交于 2023-05-19 22:15 . 加入健康检查
using Microsoft.Extensions.Diagnostics.HealthChecks;
using System.Threading.Tasks;
using System.Threading;
using System;
using Microsoft.Extensions.Options;
public class VLPRHealthCheck : IHealthCheck
{
private readonly VLPROptions options;
private readonly VLPRClient client;
public VLPRHealthCheck(IOptions<VLPROptions> options, VLPRClient client)
{
this.options = options.Value;
this.client = client;
}
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
List<(string name, bool ok)> lst = new List<(string name, bool ok)>();
options.VLPRConfigs.ForEach(config =>
{
var ok = client.CheckStatus(config.Name);
lst.Add((config.Name, ok));
});
if (lst.All(f => !f.ok))
{
return Task.FromResult(HealthCheckResult.Unhealthy(description: string.Join(";", lst.Select(c => $"车道:{c.name} {(c.ok ? "正常" : "故障")}").ToList())));
}
else if (lst.Any(f => !f.ok))
{
return Task.FromResult(HealthCheckResult.Degraded(description: string.Join(";", lst.Select(c => $"车道:{c.name} {(c.ok ? "正常" : "故障")}").ToList())));
}
else
{
return Task.FromResult(HealthCheckResult.Healthy());
}
}
}
C#
1
https://gitee.com/IoTSharp/VLPR.git
git@gitee.com:IoTSharp/VLPR.git
IoTSharp
VLPR
VLPR
master

搜索帮助