Class CronTriggerImpl
A concrete ITrigger that is used to fire a IJobDetail at given moments in time, defined with Unix 'cron-like' definitions.
[Serializable]
public class CronTriggerImpl : TriggerBase, IOperableTrigger, IMutableTrigger, IEquatable<TriggerBase>, ICronTrigger, ITrigger
- Inheritance
-
CronTriggerImpl
- Implements
- Inherited Members
Remarks
For those unfamiliar with "cron", this means being able to create a firing schedule such as: "At 8:00am every Monday through Friday" or "At 1:30am every last Friday of the month".
The format of a "Cron-Expression" string is documented on the CronExpression class.
Here are some full examples:
| Expression | Meaning | |
|---|---|---|
| "0 0 12 * * ?"" /> | Fire at 12pm (noon) every day" /> | |
| "0 15 10 ? * *"" /> | Fire at 10:15am every day" /> | |
| "0 15 10 * * ?"" /> | Fire at 10:15am every day" /> | |
| "0 15 10 * * ? *"" /> | Fire at 10:15am every day" /> | |
| "0 15 10 * * ? 2005"" /> | Fire at 10:15am every day during the year 2005" /> | |
| "0 * 14 * * ?"" /> | Fire every minute starting at 2pm and ending at 2:59pm, every day" /> | |
| "0 0/5 14 * * ?"" /> | Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day" /> | |
| "0 0/5 14,18 * * ?"" /> | Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day" /> | |
| "0 0-5 14 * * ?"" /> | Fire every minute starting at 2pm and ending at 2:05pm, every day" /> | |
| "0 10,44 14 ? 3 WED"" /> | Fire at 2:10pm and at 2:44pm every Wednesday in the month of March." /> | |
| "0 15 10 ? * MON-FRI"" /> | Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday" /> | |
| "0 15 10 15 * ?"" /> | Fire at 10:15am on the 15th day of every month" /> | |
| "0 15 10 L * ?"" /> | Fire at 10:15am on the last day of every month" /> | |
| "0 15 10 ? * 6L"" /> | Fire at 10:15am on the last Friday of every month" /> | |
| "0 15 10 ? * 6L"" /> | Fire at 10:15am on the last Friday of every month" /> | |
| "0 15 10 ? * 6L 2002-2005"" /> | Fire at 10:15am on every last Friday of every month during the years 2002, 2003, 2004 and 2005" /> | |
| "0 15 10 ? * 6#3"" /> | Fire at 10:15am on the third Friday of every month" /> |
Pay attention to the effects of '?' and '*' in the day-of-week and day-of-month fields!
NOTES:
- Support for specifying both a day-of-week and a day-of-month value is not complete (you'll need to use the '?' character in on of these fields).
- Be careful when setting fire times between mid-night and 1:00 AM - "daylight savings" can cause a skip or a repeat depending on whether the time moves back or jumps forward.
Constructors
CronTriggerImpl(string, string, string, TimeProvider?)
Create a CronTriggerImpl with the given name, group and expression.
public CronTriggerImpl(string name, string group, string cronExpression, TimeProvider? timeProvider = null)
Parameters
namestringThe name of the ITrigger
groupstringThe group of the ITrigger
cronExpressionstringA cron expression dictating the firing sequence of the ITrigger
timeProviderTimeProviderA TimeProvider to use, if not specified defaults to TimeProvider.System
Remarks
The start-time will also be set to the current time, and the time zone
will be set to the system's default time zone. Everything else this trigger
needs is a settable property, so the object-initializer form
new CronTriggerImpl { Key = ..., JobKey = ..., EndTimeUtc = ... } replaces
the constructor overloads that used to spell out each combination.
Exceptions
- ArgumentNullException
nameorgroupare null.
CronTriggerImpl(TimeProvider?)
Create a CronTriggerImpl with no settings.
public CronTriggerImpl(TimeProvider? timeProvider = null)
Parameters
timeProviderTimeProviderTime provider instance to use, defaults to System
Remarks
The start-time will also be set to the current time, and the time zone will be set to the system's default time zone.
Properties
CronExpression
Set the CronExpression to the given one. The TimeZone on the passed-in CronExpression over-rides any that was already set on the Trigger.
public CronExpression? CronExpression { get; set; }
Property Value
- CronExpression
The cron expression.
CronExpressionString
Gets or sets the cron expression string.
public string? CronExpressionString { get; set; }
Property Value
- string
The cron expression string.
EndTimeUtc
Get or sets the time at which the CronTrigger should quit
repeating - even if repeatCount isn't yet satisfied.
public override DateTimeOffset? EndTimeUtc { get; set; }
Property Value
FinalFireTimeUtc
Returns the last UTC time at which the ITrigger will fire, if the Trigger will repeat indefinitely, null will be returned.
Note that the return time *may* be in the past.
public override DateTimeOffset? FinalFireTimeUtc { get; }
Property Value
HasMillisecondPrecision
Tells whether this Trigger instance can handle events in millisecond precision.
protected override bool HasMillisecondPrecision { get; }
Property Value
MayFireAgain
Used by the IScheduler to determine whether or not it is possible for this ITrigger to fire again.
If the returned value is false then the IScheduler may remove the ITrigger from the IJobStore.
public override bool MayFireAgain { get; }
Property Value
MisfireInstruction
What the scheduler does when this trigger misses a firing.
public CronTriggerMisfireInstruction MisfireInstruction { get; }
Property Value
- See Also
NextFireTimeUtc
Returns the next time at which the ITrigger is scheduled to fire. If the trigger will not fire again, null will be returned. Note that the time returned can possibly be in the past, if the time that was computed for the trigger to next fire has already arrived, but the scheduler has not yet been able to fire the trigger (which would likely be due to lack of resources e.g. threads).
public override DateTimeOffset? NextFireTimeUtc { get; set; }
Property Value
Remarks
The value returned is not guaranteed to be valid until after the ITrigger has been added to the scheduler.
PreviousFireTimeUtc
Returns the previous time at which the ITrigger fired. If the trigger has not yet fired, null will be returned.
public override DateTimeOffset? PreviousFireTimeUtc { get; set; }
Property Value
StartTimeUtc
Returns the date/time on which the trigger may begin firing. This defines the initial boundary for trigger firings the trigger will not fire prior to this date and time.
public override DateTimeOffset StartTimeUtc { get; set; }
Property Value
TimeZone
Sets the time zone for which the CronExpressionString of this ICronTrigger will be resolved.
public TimeZoneInfo TimeZone { get; set; }
Property Value
- TimeZoneInfo
The time zone.
Remarks
If CronExpressionString is set after this property, the TimeZone setting on the CronExpression will "win". However if CronExpressionString is set after this property, the time zone applied by this method will remain in effect, since the string cron expression does not carry a time zone!
Methods
Clone()
Clones this instance.
public override ITrigger Clone()
Returns
ComputeFirstFireTimeUtc(ICalendar?)
Called by the scheduler at the time a ITrigger is first added to the scheduler, in order to have the ITrigger compute its first fire time, based on any associated calendar.
After this method has been called, NextFireTimeUtc should return a valid answer.
public override DateTimeOffset? ComputeFirstFireTimeUtc(ICalendar? calendar)
Parameters
calendarICalendar
Returns
- DateTimeOffset?
the first time at which the ITrigger will be fired by the scheduler, which is also the same value NextFireTimeUtc will return (until after the first firing of the ITrigger).
GetFireTimeAfter(DateTimeOffset?)
Returns the next time at which the ITrigger will fire, after the given time. If the trigger will not fire after the given time, null will be returned.
public override DateTimeOffset? GetFireTimeAfter(DateTimeOffset? afterTimeUtc)
Parameters
afterTimeUtcDateTimeOffset?
Returns
GetPreviousValidTimeBefore(DateTimeOffset)
Returns the time before the given time that this ICronTrigger will fire.
protected DateTimeOffset? GetPreviousValidTimeBefore(DateTimeOffset date)
Parameters
dateDateTimeOffsetThe date.
Returns
GetScheduleBuilder()
Get a IScheduleBuilder that is configured to produce a schedule identical to this trigger's schedule.
public override IScheduleBuilder GetScheduleBuilder()
Returns
Triggered(ICalendar?)
Called when the IScheduler has decided to 'fire' the trigger (Execute the associated IJob), in order to give the ITrigger a chance to update itself for its next triggering (if any).
public override void Triggered(ICalendar? calendar)
Parameters
calendarICalendar
- See Also
UpdateAfterMisfire(ICalendar?)
This method should not be used by the Quartz client.
To be implemented by the concrete classes that extend this class.
The implementation should update the ITrigger's state according to the misfire instruction the ITrigger was built with, read as MisfireInstructionCode.
public override void UpdateAfterMisfire(ICalendar? calendar)
Parameters
calendarICalendar
UpdateWithNewCalendar(ICalendar, TimeSpan)
Updates the trigger with new calendar.
public override void UpdateWithNewCalendar(ICalendar calendar, TimeSpan misfireThreshold)
Parameters
ValidateMisfireInstruction(int)
Validates the misfire instruction.
protected override bool ValidateMisfireInstruction(int misfireInstruction)
Parameters
misfireInstructionintThe misfire instruction.
Returns
WillFireOn(DateTimeOffset, bool)
Determines whether the date and (optionally) time of the given Calendar instance falls on a scheduled fire-time of this trigger.
Note that the value returned is NOT validated against the related ICalendar (if any).
public bool WillFireOn(DateTimeOffset timeUtc, bool dayOnly = false)
Parameters
timeUtcDateTimeOffsetThe time to compare.
dayOnlyboolIf set to true, the method will only determine if the trigger will fire during the day represented by the given Calendar (hours, minutes and seconds will be ignored).