5 (30.11.2022 3m) Flashcards
Describe exception handling for Quartz.Net jobs.
The only type of exception that you should throw from the execute method is the JobExecutionException.
Because of this, you should generally wrap the entire contents of the execute method with a ‘try-catch’ block.
JobExecutionException can be used to provide the scheduler with various directives as to how you want the exception to be handled.
JobExecutionException
What are trigger StartTimeUtc and EndTimeUtc for?
The StartTimeUtc property indicates when the trigger’s schedule first comes into effect. The value is a DateTimeOffset object that defines a moment in time on a given calendar date. For some trigger types, the trigger will actually fire at the start time, for others, it simply marks the time that the schedule should start being followed. This means you can store a trigger with a schedule such as “every 5th day of the month” during January, and if the StartTimeUtc property is set to April 1st, it will be a few months before the first firing.
The EndTimeUtc property indicates when the trigger’s schedule should no longer be in effect. In other words, a trigger with a schedule of “every 5th day of the month” and with an end time of July 1st will fire for its last time on June 5th.
Describe trigger priority. What is recovery priority?
Sometimes, when you have many Triggers (or few worker threads in your Quartz.NET thread pool), Quartz.NET may not have enough resources to immediately fire all of the Triggers that are scheduled to fire at the same time. In this case, you may want to control which of your Triggers gets the first crack at the available Quartz.NET worker threads. For this purpose, you can set the priority property on a Trigger.
For example. If N Triggers are to fire at the same time, but there are only Z worker threads currently available, then the first Z Triggers with the highest priority will be executed first.
If you do not set a priority on a Trigger, then it will use the default priority of 5. Any integer value is allowed for priority, positive or negative. A larger number indicates a higher priority. i.e. A trigger with a Priority of 7 will have priority over a trigger with a value of 5.
Priorities are only compared when triggers have the same fire time. A trigger scheduled to fire at 10:59 will always fire before one is scheduled to fire at 11:00.
When a trigger’s job is detected to require recovery, its recovery is scheduled with the same priority as the original trigger.
Describe trigger Misfire Instructions concept. What is MisfireThreshold? What is misfire instruction?
Sometimes Quartz is not capable of running your job at the time when you desired. There are three reasons for that:
- all worker threads were busy running other jobs (probably with higher priority)
- the scheduler itself was down
- the job was scheduled with start time in the past (probably a coding error)
The situation when Quartz was incapable of firing a given trigger at desired time is called misfire.
The MisfireThreshold option (in milliseconds) defines how late the trigger should be to be considered misfired. The default value is 60000 (a minute). With the default setup, if a trigger was supposed to be fired 30 seconds ago, Quartz will happily just run it. Such delay is not considered misfiring. However, if the trigger is discovered 61 seconds after the scheduled time - the special misfire handler takes care of it.
The option defining the way of misfire handling is called misfire instruction.
Note: if a job started in time but was not able to finish in MisfireThreshold this is not counted as misfire and no misfire handling will be involved.