refactor: 精简代码修正检查项顺序

This commit is contained in:
Argo Zhang 2019-08-13 20:23:28 +08:00
parent fb30940a6b
commit ee702157db
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
2 changed files with 16 additions and 7 deletions

View File

@ -1,6 +1,7 @@
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using Bootstrap.Security; using Bootstrap.Security;
using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Diagnostics.HealthChecks;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -25,7 +26,13 @@ namespace Bootstrap.Admin.HealthChecks
{ {
var connStr = db.ConnectionString; var connStr = db.ConnectionString;
var dicts = db.Fetch<BootstrapDict>("Select * from Dicts"); 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"));
} }
} }
} }

View File

@ -32,12 +32,14 @@ namespace Bootstrap.Admin.HealthChecks
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) 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 file = _env.IsDevelopment() ? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Longbow.lic") : Path.Combine(_env.ContentRootPath, "Longbow.lic");
var data = new Dictionary<string, object>(); var data = new Dictionary<string, object>
data.Add("ContentRootPath", _env.ContentRootPath); {
data.Add("WebRootPath", _env.WebRootPath); { "ApplicationName", _env.ApplicationName },
data.Add("ApplicationName", _env.ApplicationName); { "EnvironmentName", _env.EnvironmentName },
data.Add("EnvironmentName", _env.EnvironmentName); { "ContentRootPath", _env.ContentRootPath },
data.Add("CheckFile", file); { "WebRootPath", _env.WebRootPath },
{ "CheckFile", file }
};
return Task.FromResult(File.Exists(file) ? HealthCheckResult.Healthy("Ok", data) : HealthCheckResult.Unhealthy($"Missing file {file}", null, data)); return Task.FromResult(File.Exists(file) ? HealthCheckResult.Healthy("Ok", data) : HealthCheckResult.Unhealthy($"Missing file {file}", null, data));
} }
} }