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