程序启动时定时任务不立即执行 修改调度数据时立即生效 生成点巡检计划精度补齐
This commit is contained in:
@@ -60,13 +60,18 @@ namespace JNPF.TaskScheduler.Listener
|
||||
// }
|
||||
// }
|
||||
|
||||
//丢失精度补齐 例如设定10分钟执行 但是这个破框架会再9:59 时进入这个方法导致不能正常执行
|
||||
//精确到分的定时任务可以不使用本地任务 采用数据接口的方式规避掉这个问题
|
||||
int second = DateTime.Now.Second;//当前的秒数
|
||||
int offsetMinute = second > 30 ? 1 : 0;
|
||||
|
||||
//整除表示一个周期到了
|
||||
foreach (var item in eqpSpotInsTemEquipHsByCirculate)
|
||||
{
|
||||
TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm")).Ticks);
|
||||
TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(item.start_time.ToString("yyyy-MM-dd HH:mm")).Ticks);
|
||||
TimeSpan ts3 = ts1.Subtract(ts2).Duration();
|
||||
if (ts3.TotalMinutes * 10 / 60 % (10 * (double)item.plan_cycle)==0)
|
||||
if ((ts3.TotalMinutes+offsetMinute) * 10 / 60 % (10 * (double)item.plan_cycle)==0)
|
||||
{
|
||||
tobeCreateTemplets.Add(item);
|
||||
}
|
||||
|
||||
@@ -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(x=>AddTimerJob(x,false));//modifyby zhoukeda 20230607
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
|
||||
/// 新增定时任务.
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
private async void AddTimerJob(TimeTaskEntity input)
|
||||
private async void AddTimerJob(TimeTaskEntity input,bool startNow = true)
|
||||
{
|
||||
Action<SpareTimer, long>? action = null;
|
||||
ContentModel? comtentModel = input.ExecuteContent.ToObject<ContentModel>();
|
||||
@@ -369,7 +369,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
|
||||
{
|
||||
interval = (starTime.ParseToDateTime() - DateTime.Now).TotalMilliseconds.ParseToInt();
|
||||
}
|
||||
if (taskMethod.StartNow) //modifyby zhoukeda 20230516
|
||||
if (startNow) //modifyby zhoukeda 20230516
|
||||
{
|
||||
SpareTime.DoOnce(interval, action, "Once_" + input.Id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user