feat: 增加健康检查开关

This commit is contained in:
Argo Zhang 2020-03-05 21:43:52 +08:00
parent 8142953979
commit 12f63aac31
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
6 changed files with 32 additions and 3 deletions

View File

@ -31,6 +31,7 @@ namespace Bootstrap.Admin.Models
IPCachePeriod = DictHelper.RetrieveLocaleIPSvrCachePeriod();
EnableDemo = DictHelper.RetrieveSystemModel();
AdminPathBase = DictHelper.RetrievePathBase();
EnableHealth = DictHelper.RetrieveHealth();
var dicts = DictHelper.RetrieveDicts();
Apps = DictHelper.RetrieveApps().Where(d => !d.Key.Equals("BA", StringComparison.OrdinalIgnoreCase)).Select(k =>
@ -109,5 +110,10 @@ namespace Bootstrap.Admin.Models
/// 获得/设置 系统应用程序集合
/// </summary>
public IEnumerable<(string Key, string Name, string Url)> Apps { get; set; }
/// <summary>
/// 获得/设置 是否开启健康检查
/// </summary>
public bool EnableHealth { get; set; }
}
}

View File

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using System;
@ -129,7 +130,10 @@ namespace Bootstrap.Admin
{
endpoints.MapHub<SignalRHub>("/NotiHub");
endpoints.MapHub<TaskLogHub>("/TaskLogHub");
endpoints.MapBootstrapHealthChecks();
endpoints.MapBootstrapHealthChecks("/Healths", configure: op =>
{
op.Predicate = new Func<HealthCheckRegistration, bool>(reg => DictHelper.RetrieveHealth());
});
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
endpoints.MapDefaultControllerRoute();

View File

@ -113,6 +113,10 @@
<label class="control-label" for="tableHeader">固定表头</label>
<input id="tableHeader" hidden type="checkbox" data-default-val="@Model.FixedTableHeader" data-toggle="toggle" data-width="120" data-onstyle="success" data-on="固定" data-off="跟随" />
</div>
<div class="form-group col-6">
<label class="control-label" for="health">健康检查</label>
<input id="health" hidden type="checkbox" data-default-val="@Model.EnableHealth" data-toggle="toggle" data-width="120" data-onstyle="success" data-on="开启" data-off="关闭" />
</div>
</div>
</div>
<div class="modal-footer text-right">

View File

@ -59,11 +59,13 @@ $(function () {
var uiSettings = $('#sider').prop('checked') ? "1" : "0";
var cardTitle = $('#cardTitle').prop('checked') ? "1" : "0";
var fixedTableHeader = $('#tableHeader').prop('checked') ? "1" : "0";
var enableHealth = $('#health').prop('checked') ? "1" : "0";
$.bc({
url: Settings.url, data: [
{ name: 'ShowCardTitle', code: cardTitle },
{ name: 'ShowSideBar', code: uiSettings },
{ name: 'FixedTableHeader', code: fixedTableHeader }
{ name: 'FixedTableHeader', code: fixedTableHeader },
{ name: 'EnableHealth', code: enableHealth }
], title: '保存网站设置', method: "post",
callback: function (result) {
if (result) {

View File

@ -319,5 +319,11 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <returns></returns>
public string RetrievePathBase() => DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "后台地址" && d.Define == 0)?.Code ?? "";
/// <summary>
/// 获得字典表健康检查是否开启
/// </summary>
/// <returns></returns>
public bool RetrieveHealth() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "健康检查" && d.Define == 0)?.Code ?? "0") == "1";
}
}

View File

@ -164,7 +164,8 @@ namespace Bootstrap.DataAccess
["TraceLog"] = "访问日志保留时长",
["CookiePeriod"] = "Cookie保留时长",
["IPCachePeriod"] = "IP请求缓存时长",
["AppPath"] = "后台地址"
["AppPath"] = "后台地址",
["EnableHealth"] = "健康检查"
};
var ret = SaveSettings(items.Where(i => cache.Any(c => c.Key == i.Name)).Select(i => new BootstrapDict()
{
@ -384,6 +385,12 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static string RetrievePathBase() => DbContextManager.Create<Dict>()?.RetrievePathBase() ?? "";
/// <summary>
/// 获得字典表健康检查是否开启
/// </summary>
/// <returns></returns>
public static bool RetrieveHealth() => DbContextManager.Create<Dict>()?.RetrieveHealth() ?? true;
/// <summary>
/// 保存前台应用配置信息
/// </summary>