Merge branch 'master' into net6.0
This commit is contained in:
@@ -56,7 +56,7 @@ namespace ZR.Tasks
|
||||
JobMessage = logMsg
|
||||
};
|
||||
|
||||
RecordTaskLog(context, logModel);
|
||||
await RecordTaskLog(context, logModel);
|
||||
return logModel;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace ZR.Tasks
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="logModel"></param>
|
||||
protected void RecordTaskLog(IJobExecutionContext context, SysTasksLog logModel)
|
||||
protected async Task RecordTaskLog(IJobExecutionContext context, SysTasksLog logModel)
|
||||
{
|
||||
var tasksLogService = (ISysTasksLogService)App.GetRequiredService(typeof(ISysTasksLogService));
|
||||
var taskQzService = (ISysTasksQzService)App.GetRequiredService(typeof(ISysTasksQzService));
|
||||
@@ -74,15 +74,15 @@ namespace ZR.Tasks
|
||||
IJobDetail job = context.JobDetail;
|
||||
|
||||
logModel.InvokeTarget = job.JobType.FullName;
|
||||
logModel = tasksLogService.AddTaskLog(job.Key.Name, logModel);
|
||||
logModel = await tasksLogService.AddTaskLog(job.Key.Name, logModel);
|
||||
//成功后执行次数+1
|
||||
if (logModel.Status == "0")
|
||||
{
|
||||
taskQzService.Update(f => f.ID == job.Key.Name, f => new SysTasksQz()
|
||||
await taskQzService.UpdateAsync(f => new SysTasksQz()
|
||||
{
|
||||
RunTimes = f.RunTimes + 1,
|
||||
LastRunTime = DateTime.Now
|
||||
});
|
||||
}, f => f.ID == job.Key.Name);
|
||||
}
|
||||
logger.Info($"执行任务【{job.Key.Name}|{logModel.JobName}】结果={logModel.JobMessage}");
|
||||
}
|
||||
|
||||
@@ -123,6 +123,10 @@ namespace ZR.Tasks
|
||||
{
|
||||
return ApiResult.Error(500, $"该计划任务已经在执行:【{tasksQz.Name}】,请勿重复添加!");
|
||||
}
|
||||
if (tasksQz?.EndTime <= DateTime.Now)
|
||||
{
|
||||
return ApiResult.Error(500, $"结束时间小于当前时间计划将不会被执行");
|
||||
}
|
||||
#region 设置开始时间和结束时间
|
||||
|
||||
tasksQz.BeginTime = tasksQz.BeginTime == null ? DateTime.Now : tasksQz.BeginTime;
|
||||
@@ -166,10 +170,12 @@ namespace ZR.Tasks
|
||||
// 5、将触发器和任务器绑定到调度器中
|
||||
await _scheduler.Result.ScheduleJob(job, trigger);
|
||||
//任务没有启动、暂停任务
|
||||
if (!tasksQz.IsStart)
|
||||
{
|
||||
_scheduler.Result.PauseJob(jobKey).Wait();
|
||||
}
|
||||
//if (!tasksQz.IsStart)
|
||||
//{
|
||||
// _scheduler.Result.PauseJob(jobKey).Wait();
|
||||
//}
|
||||
//按新的trigger重新设置job执行
|
||||
await _scheduler.Result.ResumeTrigger(trigger.Key);
|
||||
return ApiResult.Success($"启动计划任务:【{tasksQz.Name}】成功!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user