Lesson four more about triggers
Like job tasks, triggers are very easy to use, but before you can fully master quartz, you need to know and understand the customized parameters of many triggers. As mentioned earlier, there are many different types of triggers for you to choose from, and different scheduling requirements apply.
You will learn these two commonly used trigger types in the fifth lesson, simple trigger and sixth lesson triggers.
Trigger Common Properties
The following list of properties is common to all types of triggers:
Jobkey represents the identity of the job instance, and the specified job instance executes when the trigger is triggered. The
Starttimeutc property represents the time when the trigger's timesheet was first triggered. Its value is the DateTimeOffset object defined by the specified calendar time. For some types of triggers, triggers are triggered at startup time, while others simply indicate when the scheduler will be triggered. This means that you can store a trigger in the scheduler, such as number 5th per month, if it is January, and the StartTime parameter is set to April 1, it will take several months for the trigger to be triggered for the first time. The
ENDTIMEUTC property specifies the time at which the trigger is no longer triggered, in other words, the trigger in the scheduler is defined as "number 5th per month" and Endtime is set to July 1 , then June 5 will be the date of the last trigger.
Other properties, a more detailed explanation will be discussed in the next sub-chapters.
priority (priority)
Sometimes when you have many triggers (or only a few worker threads in the quartz thread pool), quartz may not have enough resources to trigger all the triggers that are scheduled in the same time period. In this case, you might expect to control which trigger will be the first to get the call of the quartz idle worker thread. For this purpose, you can set the priority property of the trigger. If n triggers are triggered at the same time, but only the Z worker thread is currently idle, the Z-trigger with the highest priority will be the first one to be triggered. If you do not prioritize the trigger, it will use the default priority, with a priority value of 5. Any integer type can be a priority, and a positive negative number can.
Tip: The priority is only used to compare triggers that are triggered at the same time. A trigger that is scheduled to be triggered at 10:59 is always executed first than the trigger scheduled at 11:00.
Tip: When a trigger's job task discovery sets the request recovery parameters, the restore schedule executes at the same priority as the original.
Trigger failed command
Another important attribute of a trigger is "misfireinstruction". The triggering failure occurs because the scheduler is shut down causing the stored trigger to miss the trigger time, or because the quartz line Cheng There is no idle thread to perform the job task. Different types of triggers have different triggering failure handling mechanisms. The smart policy directive is used by default-a dynamic mechanism based on trigger type and configuration. When the scheduler starts, it queries all stored triggers that trigger failures, and then updates the trigger based on the respective configured trigger failure instructions. When you start using quartz in your project , you should familiarize yourself with the triggering failure directives and the documentation interpretations on the API defined on the given trigger type . More details about triggering failure instructions will be detailed in each of the trigger type courses in the tutorial.
Calendars (Calendar)
The Quartz calendar object can be associated with a trigger when the trigger is created and stored in the scheduler. Calendars are convenient for time periods that are not included in the trigger schedule definition. For example, you can create a trigger that defines a task that triggers a job at 9:30 each weekday, plus a calendar table that excludes all the holidays.
The Calendar object can be any serializable object that implements the calendar interface, as follows:
Calendar interface
1 namespaceQuartz2 {3 Public InterfaceICalendar4 {5 stringDescription {Get;Set; }6 7ICalendar Calendarbase {Set;Get; }8 9 BOOListimeincluded (DateTimeOffset timeutc);Ten One DateTime GETNEXTINCLUDEDTIMEUTC (DateTimeOffset timeutc); A } -}
The calendar instantiation and registration into the scheduler must pass the Addcalendar method. If you use Holidaycalendar, after initializing the object, you should use the Addexcludeddate (datedate) method to easily add the dates that you want to exclude from the schedule schedule to the Calendar instance object. The same calendar instance object can be applied to multiple triggers, such as the following code:
1Holidaycalendar cal =NewHolidaycalendar ();2 Cal. Addexcludeddate (somedate);3 4Sched. Addcalendar ("myholidays", Cal,false);5 6Itrigger T =triggerbuilder.create ()7. Withidentity ("Mytrigger")8. Forjob ("MyJob")9. Withschedule (Cronschedulebuilder.dailyathourandminute (9, -))//execute job daily at 9:30amTen. Modifiedbycalendar ("myholidays")//But not on holidays One . Build (); A - //.. schedule job with Trigger - theItrigger t2 =triggerbuilder.create () -. Withidentity ("MyTrigger2") -. Forjob ("MyJob2") -. Withschedule (Cronschedulebuilder.dailyathourandminute ( One, -))//Execute job daily at +. Modifiedbycalendar ("myholidays")//But not on holidays - . Build (); + A //.. schedule job with Trigger2
About the trigger structure/build details will be described in the next two sessions. Now, just believe that the above code creates two trigger objects, each of which is triggered on a daily basis. However, any triggers that occur within the date excluded from the Calendar object will be skipped.
You can consult several Calendar implementation classes under the Quartz.Impl.Calendar package directory, and estimate the classes that are appropriate for your needs
Translation Quartz.net Framework Tutorial (Chinese Version) 2.2.x Lesson IV more about triggers