refactor: 精简代码修正检查项顺序
This commit is contained in:
parent
fb30940a6b
commit
ee702157db
|
@ -1,6 +1,7 @@
|
|||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -25,7 +26,13 @@ namespace Bootstrap.Admin.HealthChecks
|
|||
{
|
||||
var connStr = db.ConnectionString;
|
||||
var dicts = db.Fetch<BootstrapDict>("Select * from Dicts");
|
||||
return dicts.Any() ? Task.FromResult(HealthCheckResult.Healthy("Ok")) : Task.FromResult(HealthCheckResult.Degraded("No init data in DB"));
|
||||
var data = new Dictionary<string, object>()
|
||||
{
|
||||
{ "ConnectionString", connStr },
|
||||
{ "DbType", db.Provider.GetType().Name },
|
||||
{ "Dicts", dicts.Count }
|
||||
};
|
||||
return dicts.Any() ? Task.FromResult(HealthCheckResult.Healthy("Ok", data)) : Task.FromResult(HealthCheckResult.Degraded("No init data in DB"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,12 +32,14 @@ namespace Bootstrap.Admin.HealthChecks
|
|||
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var file = _env.IsDevelopment() ? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Longbow.lic") : Path.Combine(_env.ContentRootPath, "Longbow.lic");
|
||||
var data = new Dictionary<string, object>();
|
||||
data.Add("ContentRootPath", _env.ContentRootPath);
|
||||
data.Add("WebRootPath", _env.WebRootPath);
|
||||
data.Add("ApplicationName", _env.ApplicationName);
|
||||
data.Add("EnvironmentName", _env.EnvironmentName);
|
||||
data.Add("CheckFile", file);
|
||||
var data = new Dictionary<string, object>
|
||||
{
|
||||
{ "ApplicationName", _env.ApplicationName },
|
||||
{ "EnvironmentName", _env.EnvironmentName },
|
||||
{ "ContentRootPath", _env.ContentRootPath },
|
||||
{ "WebRootPath", _env.WebRootPath },
|
||||
{ "CheckFile", file }
|
||||
};
|
||||
return Task.FromResult(File.Exists(file) ? HealthCheckResult.Healthy("Ok", data) : HealthCheckResult.Unhealthy($"Missing file {file}", null, data));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue