fix 优化健康检查,数据同步
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Dlhis.Middle.Apis;
|
||||
using Dlhis.Middle.Entities;
|
||||
using Dlhis.Middle.Response;
|
||||
using Dlhis.Middle.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Middle.BackgroundServices;
|
||||
|
||||
@@ -102,6 +98,8 @@ public class BalanceRecordUploadBackgroundService : BackgroundService
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (now is { Hour: 4, Minute: 1 }
|
||||
&& !_healthCheckService.GetIsOffline()
|
||||
&& !await db.Queryable<LocalBalanceRecordEntity>().Where(x => !x.IsSync).AnyAsync())
|
||||
@@ -121,6 +119,11 @@ public class BalanceRecordUploadBackgroundService : BackgroundService
|
||||
await ds.InitAsync(factories);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "定时同步离线数据失败");
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(60 * 1000, stoppingToken);
|
||||
}
|
||||
|
||||
@@ -5,17 +5,31 @@ namespace Dlhis.Middle.BackgroundServices;
|
||||
public class HealthCheckBackgroundService : BackgroundService
|
||||
{
|
||||
private readonly IHealthCheckService _healthCheckService;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private bool _init;
|
||||
|
||||
public HealthCheckBackgroundService(IHealthCheckService healthCheckService)
|
||||
public HealthCheckBackgroundService(IHealthCheckService healthCheckService, IServiceProvider serviceProvider)
|
||||
{
|
||||
_healthCheckService = healthCheckService;
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
await _healthCheckService.DoHealthCheckAsync();
|
||||
if (await _healthCheckService.DoHealthCheckAsync())
|
||||
{
|
||||
if (!_init)
|
||||
{
|
||||
using var scope = _serviceProvider.CreateScope();
|
||||
var factories = scope.ServiceProvider.GetService<ISettingService>().GetFactories();
|
||||
var ds = scope.ServiceProvider.GetService<IDataDownloadService>();
|
||||
await ds.InitAsync(factories);
|
||||
}
|
||||
}
|
||||
|
||||
_init = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Middle.Entities;
|
||||
using Dlhis.Middle.Entities;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Attributes;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Dlhis.Middle.BackgroundServices;
|
||||
using Dlhis.Middle.Services;
|
||||
using Kurisu.AspNetCore;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
@@ -31,18 +30,4 @@ public class Startup : DefaultStartup
|
||||
services.AddRemoteCall(App.ActiveTypes);
|
||||
services.AddMemoryCache();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
base.Configure(app, env);
|
||||
|
||||
if (Configuration.GetSection("Download").Value == "1")
|
||||
{
|
||||
using var scope = app.ApplicationServices.CreateScope();
|
||||
var factories = scope.ServiceProvider.GetService<ISettingService>().GetFactories();
|
||||
var ds = scope.ServiceProvider.GetService<IDataDownloadService>();
|
||||
ds.InitAsync(factories).Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,5 @@ public interface IHealthCheckService : ISingletonDependency
|
||||
{
|
||||
bool GetIsOffline();
|
||||
|
||||
Task DoHealthCheckAsync();
|
||||
Task<bool> DoHealthCheckAsync();
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class HealthCheckService : IHealthCheckService
|
||||
return _isOffline;
|
||||
}
|
||||
|
||||
public async Task DoHealthCheckAsync()
|
||||
public async Task<bool> DoHealthCheckAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -50,12 +50,13 @@ public class HealthCheckService : IHealthCheckService
|
||||
_isBegin = true;
|
||||
}
|
||||
|
||||
await Task.Delay(_attempted * 1000);
|
||||
|
||||
if (_isOffline == false)
|
||||
{
|
||||
_logger.LogInformation("Health");
|
||||
return true;
|
||||
}
|
||||
|
||||
await Task.Delay(_attempted * 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -69,5 +70,7 @@ public class HealthCheckService : IHealthCheckService
|
||||
_isOffline = true;
|
||||
await Task.Delay(5000);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,5 @@
|
||||
},
|
||||
"BaseUrl": "https://yikatong.isawesome.cn",
|
||||
"Factory": "1234",
|
||||
"Download":1
|
||||
"InternalIP":""
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user