定时任务改成根据配置是否立刻执行
This commit is contained in:
@@ -284,7 +284,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
|
||||
// 非多租户模式启动自启任务
|
||||
if (!KeyVariable.MultiTenancy)
|
||||
{
|
||||
//_repository.AsQueryable().Where(x => x.DeleteMark == null && x.EnabledMark == 1).ToList().ForEach(AddTimerJob);
|
||||
_repository.AsQueryable().Where(x => x.DeleteMark == null && x.EnabledMark == 1).ToList().ForEach(AddTimerJob);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,11 +337,12 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
|
||||
Action<SpareTimer, long>? action = null;
|
||||
ContentModel? comtentModel = input.ExecuteContent.ToObject<ContentModel>();
|
||||
input.ExecuteCycleJson = comtentModel.cron;
|
||||
TaskMethodInfo? taskMethod = null;
|
||||
switch (input.ExecuteType)
|
||||
{
|
||||
case "3":
|
||||
// 查询符合条件的任务方法
|
||||
TaskMethodInfo? taskMethod = GetTaskMethods()?.Result.FirstOrDefault(m => m.id == comtentModel.localHostTaskId);
|
||||
taskMethod = GetTaskMethods()?.Result.FirstOrDefault(m => m.id == comtentModel.localHostTaskId);
|
||||
if (taskMethod == null) break;
|
||||
|
||||
// 创建任务对象
|
||||
@@ -368,20 +369,19 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
|
||||
{
|
||||
interval = (starTime.ParseToDateTime() - DateTime.Now).TotalMilliseconds.ParseToInt();
|
||||
}
|
||||
SpareTime.DoOnce(interval, action, "Once_" + input.Id);
|
||||
SpareTime.Do(
|
||||
() =>
|
||||
{
|
||||
var isRun = comtentModel.endTime.IsNullOrEmpty() ? DateTime.Now >= starTime : DateTime.Now >= starTime && DateTime.Now < endTime;
|
||||
if (isRun)
|
||||
{
|
||||
return SpareTime.GetCronNextOccurrence(comtentModel.cron);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
},
|
||||
if (taskMethod.StartNow) //modifyby zhoukeda 20230516
|
||||
{
|
||||
SpareTime.DoOnce(interval, action, "Once_" + input.Id);
|
||||
}
|
||||
|
||||
Func<DateTimeOffset?> nextHandle = null;
|
||||
var isRun = comtentModel.endTime.IsNullOrEmpty() ? DateTime.Now >= starTime : DateTime.Now >= starTime && DateTime.Now < endTime;
|
||||
if (isRun)
|
||||
{
|
||||
nextHandle = ()=>SpareTime.GetCronNextOccurrence(comtentModel.cron);
|
||||
}
|
||||
SpareTime.Do(nextHandle
|
||||
,
|
||||
action, input.Id, comtentModel.ConnectionConfig.ToJsonString(), true, executeType: SpareTimeExecuteTypes.Parallel, cancelInNoneNextTime: false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user