The Quartz API
The key interfaces and classes of the Quartz API are:
|the main API for interacting with the scheduler|
|an interface to be implemented by components that you wish to have executed by the scheduler|
|used to define instances of Jobs|
|a component that defines the schedule upon which a given Job will be executed, job can have multiple associated triggers|
|used to define/build JobDetail instances, which define instances of Jobs|
|used to define/build Trigger instances|
|used to define/build scheduler instances, requires Quartz 3.1 or later|
In this tutorial for readability's sake following terms are used interchangeably:
Scheduler's life-cycle is bounded by it's creation, via a
SchedulerFactory and a call to its
Shutdown() method. Once created the
IScheduler interface can be used add, remove, and list Jobs and Triggers, and perform other scheduling-related operations (such as pausing a trigger). However, the Scheduler will not actually act on any triggers (execute jobs) until it has been started with the
Start() method, as shown in Lesson 1.
Quartz provides "builder" classes that define a Domain Specific Language (or DSL, also sometimes referred to as a "fluent interface"). In the previous lesson you saw an example of it, which we present a portion of here again:
// define the job and tie it to our HelloJob class IJobDetail job = JobBuilder.Create<HelloJob>() .WithIdentity(name: "myJob", group: "group1") .Build(); // Trigger the job to run now, and then every 40 seconds ITrigger trigger = TriggerBuilder.Create() .WithIdentity(name: "myTrigger", group: "group1") .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(40) .RepeatForever()) .Build(); var sched = scheduleFactory.GetScheduler(); // Tell Quartz to schedule the job using our trigger await sched.ScheduleJob(job, trigger);
The block of code that builds the job definition is using
JobBuilder to create the
IJobDetail. Likewise, the block of code that builds the trigger is using
TriggerBuilder's fluent interface to the trigger.
Possible schedule extension methods are:
DateBuilder type contains various methods for easily constructing
DateTimeOffset instances for particular points in time (such as a date that represents the next even hour - or in other words 10:00:00 if it is currently 9:43:27).