public bool RescheduleJob(string name, string cronExpression, bool startImmediately) { var schedules = GetJobSchedules(name).ToList(); if (!schedules.Any()) { LogEntry.New().Warn().Message($"Job {name.DoubleQuote()} isn't scheduled.").Log(Logger); return(false); } // Multiple schedules are not supported. var schedule0 = schedules.First(); if (schedule0 == cronExpression) { LogEntry.New().Debug().Message($"Job {name.DoubleQuote()} doesn't need to be rescheduled.").Log(Logger); return(false); } else { var trigger = TriggerFactory.CreateTrigger(name, cronExpression, startImmediately); _quartzScheduler.RescheduleJob(trigger.Key, trigger); LogEntry.New().Info().Message($"Job {name.DoubleQuote()} schedule changed from {schedule0.DoubleQuote()} to {cronExpression.DoubleQuote()}").Log(Logger); return(true); } }
public void ScheduleJob <TJob>(string name, string cronExpression, bool startImmediately) where TJob : IJob { var jobDetail = JobBuilder.Create <TJob>().WithIdentity(new JobKey(name)).Build(); var trigger = TriggerFactory.CreateTrigger(name, cronExpression, startImmediately); _quartzScheduler.ScheduleJob(jobDetail, trigger); LogEntry.New().Info().Message($"Job {name.DoubleQuote()} scheduled to {cronExpression.DoubleQuote()}.").Log(Logger); }