/// <summary> /// 在Trigger 触发后,Job 将要被执行时由 Scheduler 调用这个方法。TriggerListener 给了一个选择去否决 Job 的执行。假如这个方法返回 true,这个 Job 将不会为此次 Trigger /// 触发而得到执行 /// Called by the Quartz.IScheduler when a Quartz.ITrigger has fired, and it's associated /// Quartz.IJobDetail is about to be executed. /// It is called after the /// Quartz.ITriggerListener.TriggerFired(Quartz.ITrigger,Quartz.IJobExecutionContext,System.Threading.CancellationToken) /// method of this interface. If the implementation vetoes the execution (via returning /// true), the job's execute method will not be called. /// </summary> /// <param name="trigger"> The Quartz.ITrigger that has fired.</param> /// <param name="context"> /// The Quartz.IJobExecutionContext that will be passed to the /// Quartz.IJob'sQuartz.IJob.Execute(Quartz.IJobExecutionContext) method. /// </param> /// <param name="cancellationToken"> The cancellation instruction.</param> /// <returns> Returns true if job execution should be vetoed, false otherwise. </returns> public virtual async Task <bool> VetoJobExecution(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken = default) { Debug(nameof(ITriggerListener), nameof(VetoJobExecution)); var origJobName = context.GetJobCode(); //检查依赖选项是否满足 var isOnceJob = context.IsOnceJob(); var depJobs = context.GetDepJobs(); //jobcodes var isContinueRun = isOnceJob || string.IsNullOrEmpty(depJobs) || await WaitJobCompleted(origJobName, depJobs.Split(',').ToList(), DateTime.Now.Date); context.JobDetail.SetContinueRunFlag(isContinueRun); if (!isContinueRun) { Debug(nameof(ITriggerListener), origJobName + "未满足运行条件"); // Do Notice await DoNoticeAsync($"前置job:{depJobs} 未全部完成! "); return(await Task.FromResult(true)); } return(await Task.FromResult(false)); }