-
Notifications
You must be signed in to change notification settings - Fork 313
Migration to v6
guryanovev edited this page Feb 21, 2018
·
2 revisions
Version 6 of CrystalQuartz panel introduces few breaking changes so minor code fixes might be needed for some cases.
-
For CrystalQuartz.Owin package, the
IScheduler
instance can not be passed toUseCrystalQuartz
any more. A Func returning the scheduler should be used instead:Old Code
app.UseCrystalQuartz(scheduler);
New code
app.UseCrystalQuartz(() => scheduler);
-
For CrystalQuartz.Simple package, you would need to change your
SimpleSchedulerProvider
class (might be named differently if you customized it).Old code:
public class SimpleSchedulerProvider : StdSchedulerProvider { protected override System.Collections.Specialized.NameValueCollection GetSchedulerProperties() { var properties = base.GetSchedulerProperties(); // Place custom properties creation here: // properties.Add("test1", "test1value"); return properties; } protected override void InitScheduler(IScheduler scheduler) { // JOB_CREATION_CODE ==> var jobDetail = JobBuilder.Create<HelloJob>() .StoreDurably() .WithIdentity("myJob") .Build(); var trigger = TriggerBuilder.Create() .WithIdentity("myTrigger") .StartNow() .WithSimpleSchedule(x => x.WithIntervalInMinutes(1).RepeatForever()) .Build(); scheduler.ScheduleJob(jobDetail, trigger); // <== JOB_CREATION_CODE } }
New code:
/***** * Note #1 - ISchedulerProvider * instead of StdSchedulerProvider *****/ public class SimpleSchedulerProvider : ISchedulerProvider { /***** * Note #2 - signature change, * no GetSchedulerProperties/InitScheduler methods * any more. You should only implement CreateScheduler. *****/ public object CreateScheduler(ISchedulerEngine engine) { /***** * Note #3 - no Scheduler instance pre-created, you * should create it by yourself. *****/ ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); var scheduler = schedulerFactory.GetScheduler().Result; // .Result is for Quartz v3 // JOB_CREATION_CODE ==> var jobDetail = JobBuilder.Create<HelloJob>() .StoreDurably() .WithIdentity("myJob") .Build(); var trigger = TriggerBuilder.Create() .WithIdentity("myTrigger") .StartNow() .WithSimpleSchedule(x => x.WithIntervalInMinutes(1).RepeatForever()) .Build(); scheduler.ScheduleJob(jobDetail, trigger); // <== JOB_CREATION_CODE return scheduler; } }
-
For CrystalQuartz.Remote package - no changes needed.