Browse Source

通过配置文件去确定是否需要开启定时从极光的api获取数据,并添加对应的配置点

develop-lawyerExampaper
胡超1 2 years ago
parent
commit
ea1d2bfb3b
  1. 6
      24Hour/appsettings.json
  2. 21
      Elight.Logic/Job/QuartzHostedService.cs

6
24Hour/appsettings.json

@ -50,5 +50,11 @@
"secret": "e752e4fba67526eca21313a18c96a58f",
"secid": "e752e4fba67526eca21313a18c96a58f",
"miniprogram_state": "trial"
},
"CaseTwenty": {
"SysAddress": "http://127.0.0.1"
},
"SyncDataFromJiguang": {
"enable": "false"
}
}

21
Elight.Logic/Job/QuartzHostedService.cs

@ -2,6 +2,7 @@
using Elight.Utility.logs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Quartz;
using Quartz.Spi;
using SqlSugar;
@ -19,16 +20,30 @@ namespace Elight.Logic.Job
private readonly ISchedulerFactory _schedulerFactory;
private readonly IJobFactory _jobFactory;
private readonly WsJob _myJob;
private readonly IConfiguration configuration;
private readonly ILogger<QuartzHostedService> logger;
public QuartzHostedService(ISchedulerFactory schedulerFactory, IJobFactory jobFactory, WsJob myJob, IConfiguration configuration)
public QuartzHostedService(ISchedulerFactory schedulerFactory, IJobFactory jobFactory, WsJob myJob, IConfiguration _configuration, ILogger<QuartzHostedService> _logger)
{
_schedulerFactory = schedulerFactory;
_jobFactory = jobFactory;
_myJob = myJob;
this.configuration = _configuration;
this.logger = _logger;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
{
if (configuration.GetSection("SyncDataFromJiguang:enable").Value == "false")
{
logger.LogInformation("disabled data sync from jiguang api");
return;
}
else
{
logger.LogInformation("enable data sync from jiguang api ");
}
try
{
IScheduler scheduler = await _schedulerFactory.GetScheduler(cancellationToken);
@ -63,7 +78,7 @@ namespace Elight.Logic.Job
}
catch (Exception ex)
{
LogService.WriteLog(ex.Message+"___"+ex.InnerException, "同步程序错误");
LogService.WriteLog(ex.Message + "___" + ex.InnerException, "同步程序错误");
}
#endregion
}

Loading…
Cancel
Save