Quartz API
The key interfaces and classes of the Quartz API is:
The main interfaces and classes of the Quartz API are as follows:
- ischeduler-the primary interface for interaction with Scheduler.
- ijob-the interface to be inherited by the custom execution module, scheduler invokes the module that implements the interface.
- ijobdetail-used to define the Job instance.
- itrigger-the module used to define schedule, depending on the schedule in the module, determines which job should be executed.
- jobbuilder-Used to build jobdetail instances.
- triggerbuilder-Used to build Trigger instances.
In this tutorial, the following concepts can be replaced using: IScheduler and Scheduler, IJob and Job, Ijobdetail and Jobdetail, Itrigger and Trigger.
a scheduler instance life cycle from schedulerfactory Constructs an instance of it to start to the end of the call to it Shutdown () method. Once created, this instance can be used for add, remove, and list Jobs and Triggers  , or other actions related to scheduling (such as pausing trigger). However, it does not actually perform any triggers (run jobs) until it calls the start () method to start itself, referring to lesson 1.
Quartz provides "builder" to define a Domain specific Language (DSL, sometimes called the streaming interface "fluent interface"). There was an example in the previous lesson, and we'll list some of them below:
//define the job and tie it to our Hellojob class Ijobdetail Job = Jobbuilder.Create<Hellojob> () .withidentity("MyJob", "Group1") //Name "MyJob", Group "group1" .Build(); //Trigger The job to run now, and then every seconds Itrigger Trigger = Triggerbuilder.Create() .withidentity("Mytrigger", "Group1") .Startnow() .Withsimpleschedule(x = x .Withintervalinseconds( +) .RepeatForever()) .Build(); //Tell Quartz to schedule the job using our trigger sched.Schedulejob(Job, Trigger);
This code uses the Jobbuilder to build the job instance through the streaming interface, using the Triggerbuilder extension method to build the trigger of the specified type through the streaming interface. Schedule the available extension methods are:
- Withcalendarintervalschedule
- Withcronschedule
- Withdailytimeintervalschedule
- Withsimpleschedule
Datebuilder has a series of ways to easily construct a DateTimeOffset instance for a specific point in time (for example, the next even hour time-such as 10:00:00 if the current time is 9:43:27).
Jobs and Triggers
The Job is a class that implements the IJob, and the interface has only one simple method:
IJob interface
namespace Quartz { Public Interface IJob { void Execute(Jobexecutioncontext Context); } }
When the job's trigger is triggered, the Execute (..) method executes in scheduler's worker thread. Jobexecutioncontext is passed as a parameter to this method, which provides the job instance and the environment information when the job is allowed-a handle to the Scheduler that executes the job, a handle to the trigger that triggers the method, the job's The Jobdetail object, along with some other data items.
The Jobdetail object is built by the Quartz.net client when the job is joined scheduler (that is, your program). It contains various setup information for the job, including Jobdatamap, which holds the status information for a job instance. It is the most complete definition of the job instance and will be discussed in depth in the next lesson.
trigger is used to trigger job execution. If you want to schedule job, you need to initialize the trigger to adjust its property values to set the scheduling mode. Triggers may have jobdatamap associated with it-this can be given to Job pass parameter . Quartz offers a number of different trigger types, the most commonly used are the following Simpletrigger (interface Isimpletrigger) and Crontrigger (interface Icrontrigger).
If you need to "execute and execute only once" action, then Simpletrigger can satisfy you (perform a job only once at a specific time), or you need to trigger the job at a specific time, and then repeat the job N times for each repetition interval T. Crontrigger is useful when you want to use a calendar schedule like "Every Friday, noon" or "10:15 on the tenth day of every month."
Why Jobs and Triggers? Many task schedulers do not differentiate jobs from triggers. There are some tasks that simply define ' job ' as a single execution, or a task that is scheduled with some small job recognizer. The other is more like a mix of job and trigger. When developing Quartz, we think it is reasonable to separate the concept of schedule and job. This will have many benefits.
For example, Jobs can be built and stored in schedule without concern for trigger, and many different triggers can be associated with the job. Another benefit of this low-coupling design is the ability to configure the remaining jobs in the scheduler when all trigger expire, so that it can be re-dispatched without the need to redefine an identical job. It also allows you to redefine or modify trigger without having to define a new job.
Identities
in putting jobs and triggers registered to Quartz Scheduler Yes, they is given a unique key value of . Jobkey and Triggerkey can help us group job and trigger. So you can organize jobs in a group like "reporting jobs" and "maintenance jobs". Inside a group Jobkey or triggerkey must be unique, and the full key value is the key name plus the group name.
Now that you have a general understanding of jobs and Triggers, then you can continue to learn Lesson 3:more about Jobs & Jobdetails and Lesson 4:more about Triggers
Original
Quartz.net C # Tutorial-Lesson Two: Jobs and Triggers