public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobExecutionException, CancellationToken cancellationToken) { if (jobExecutionException != null) { return(Task.CompletedTask); } if (context == null) { throw new ArgumentNullException(); } Console.Out.WriteAsync("JobComplete at " + DateTime.Now.ToLongTimeString()); ISimpleTrigger s = (ISimpleTrigger)context.Trigger; var finishedJob = context.JobDetail; if (s.TimesTriggered == s.RepeatCount) { context.Scheduler.DeleteJob(finishedJob.Key); AlarmRouteRule rule = (AlarmRouteRule)finishedJob.JobDataMap.Get("rule"); IJobDetail nextJob = (IJobDetail)finishedJob.JobDataMap.Get("nextJob"); ITrigger nextTrigger = (ITrigger)finishedJob.JobDataMap.Get("nextTrigger"); if (nextJob == null) { return(Task.CompletedTask); } ITrigger tr = nextTrigger.GetTriggerBuilder().StartAt(DateTime.Now.AddSeconds(rule.Duration)).Build(); context.Scheduler.ScheduleJob(nextJob, tr); } return(Task.CompletedTask); }
/// <summary> /// Gets a reference to the old trigger builder and builds a new trigger using it. /// </summary> /// <param name="jobKey"></param> /// <param name="job"></param> private void RescheduleJob(JobKey jobKey, Job job) { ITrigger oldTrigger = sched.GetTrigger(new TriggerKey(job.ProjectName + "_trigger", job.JobType)); TriggerBuilder tb = oldTrigger.GetTriggerBuilder(); ITrigger newTrigger = BuildCronTrigger(tb, job); sched.RescheduleJob(oldTrigger.Key, newTrigger); }
public Task Execute(IJobExecutionContext context) { HolidayCalendar calendar = new HolidayCalendar(); DayOfWeek toDay = DateTime.Now.DayOfWeek; if ((toDay == DayOfWeek.Saturday) || (toDay == DayOfWeek.Sunday)) { calendar.AddExcludedDate(DateTime.Now); QuarztSingleton.scheduler.AddCalendar("Holiday", calendar, true, true); ITrigger trigger = QuarztSingleton.scheduler.GetTrigger(new TriggerKey("NamHTtrigger", "NamHT")).GetAwaiter().GetResult(); TriggerBuilder tb = trigger.GetTriggerBuilder(); ITrigger UpdateTrigger = tb.ModifiedByCalendar("Holiday").Build(); QuarztSingleton.scheduler.RescheduleJob(new TriggerKey("NamHTtrigger", "NamHT"), UpdateTrigger); LogsSingleton.WriteText("Hôm nay, ngày nghỉ Job đi nhậu với bạn đây.", "Quarzt"); } return(Task.FromResult("done")); }
public static void StartNow() { _trigger.GetTriggerBuilder().StartNow(); }