6 (30.11.2022 3m) Flashcards
What is the purpose of ICalendar interface? How to add ICalendar?
Using ICalendar you can define some periods of time when triggers are prevented from fiering. For example you may turn off jobs during holidays or weekend.
When you add ICalendar to scheduler you give it a name. Using this name you can reference the ICalendar from trigger.
HolidayCalendar, basically, allows you to set exact dates (like whole day) when events are prevented from fiering.
HolidayCalendar cal = new HolidayCalendar(); cal.AddExcludedDate(someDate);
await sched.AddCalendar(“myHolidays”, cal, false);
ITrigger t = TriggerBuilder.Create()
.WithIdentity(“myTrigger”)
.ForJob(“myJob”)
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(9, 30)) // execute job daily at 9:30
.ModifiedByCalendar(“myHolidays”) // but not on holidays
.Build();
// .. schedule job with trigger
ITrigger t2 = TriggerBuilder.Create()
.WithIdentity(“myTrigger2”)
.ForJob(“myJob2”)
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(11, 30)) // execute job daily at 11:30
.ModifiedByCalendar(“myHolidays”) // but not on holidays
.Build();
Tell about the main SimpleTrigger properties.
SimpleTrigger includes the next properties: a start-time, an end-time, a repeat count, and a repeat interval. All of these properties are exactly what you’d expect them to be, with only a couple of special notes related to the end-time property.
Start-time may be a date time. If you don’t specify start-time “now” is implied.
The repeat count can be zero, a positive integer, or the constant value SimpleTrigger.RepeatIndefinitely. Use ReapeatForever() extension method if you want indefinite repeats count.
The repeat interval property must be TimeSpan.Zero, or a positive TimeSpan value. Note that a repeat interval of zero will cause firings of the trigger to happen concurrently (or as close to concurrently as the scheduler can manage).
The end-time property (if it is specified) “overrides” the repeat count property.
“overrides” means if according to repeat count a trigger would fire after end-time (indefinite repeat count, big enough value for repeat count) it will actually not because end-time is specified. This can be useful if you wish to create a trigger such as one that fires every 10 seconds until a given moment in time - rather than having to compute the number of times it would repeat between the start-time and the end-time.
How to create SimpleTrigger?
SimpleTrigger instances are built using TriggerBuilder (for the trigger’s basic properties) and WithSimpleSchedule extension method (for the SimpleTrigger-specific properties).
Name SimpleTrigger misfire instructions.
MisfireInstruction.IgnoreMisfirePolicy
MisfirePolicy.SimpleTrigger.FireNow
MisfirePolicy.SimpleTrigger.RescheduleNowWithExistingRepeatCount
MisfirePolicy.SimpleTrigger.RescheduleNowWithRemainingRepeatCount
MisfirePolicy.SimpleTrigger.RescheduleNextWithRemainingCount
MisfirePolicy.SimpleTrigger.RescheduleNextWithExistingCount
The standard misfire policy is MisfirePolicy.SmartPolicy.
Tell about trigger listener.
Trigger listeners allow you to track events that happen with triggers.
Trigger-related events include trigger firings, trigger misfirings, and trigger completions (the job fired off by the trigger is finished).
public interface ITriggerListener
{
string Name { get; }
Task TriggerFired(ITrigger trigger, IJobExecutionContext context); Task VetoJobExecution(ITrigger trigger, IJobExecutionContext context); Task TriggerMisfired(ITrigger trigger);
Task TriggerComplete(ITrigger trigger, IJobExecutionContext context, int triggerInstructionCode); }