Class CronTriggerAttribute
- Namespace
- Quartz
- Assembly
- Quartz.dll
A cron schedule for the job this class declares with QuartzJobAttribute. Write it
as many times as the job has schedules; the generator emits one AddTrigger<T> call
per attribute.
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public sealed class CronTriggerAttribute : Attribute
- Inheritance
-
CronTriggerAttribute
- Inherited Members
Examples
[QuartzJob]
[CronTrigger("0 0 0/6 * * ?")]
[CronTrigger("0 0 12 ? * MON-FRI", Name = "weekday-noon", TimeZone = "Europe/Helsinki")]
public sealed class CleanupJob : IJob
{
public ValueTask Execute(IJobExecutionContext context, CancellationToken cancellationToken = default)
{
return default;
}
}
Remarks
The expression is read at build time with the parser that reads it at run time, so one that
cannot parse is QZ0001 rather than an exception while the host starts. H is
resolved against the trigger's key, exactly as it is for
WithCronSchedule — see cron expressions.
This attribute says nothing on a class that does not also carry
QuartzJobAttribute, and the generator reports QZ1003 rather than letting a
schedule be declared and silently ignored.
What it cannot say — a start or end time, a calendar, job data, a retry policy, a preferred node
— is what AddTrigger<T> is for, and the two live together: a declared job can be
given further triggers by hand.
Constructors
CronTriggerAttribute(string)
A cron schedule for the job this class declares with QuartzJobAttribute. Write it
as many times as the job has schedules; the generator emits one AddTrigger<T> call
per attribute.
public CronTriggerAttribute(string cronExpression)
Parameters
cronExpressionstringThe cron expression the trigger fires on, in Quartz's six- or seven-field form.
Examples
[QuartzJob]
[CronTrigger("0 0 0/6 * * ?")]
[CronTrigger("0 0 12 ? * MON-FRI", Name = "weekday-noon", TimeZone = "Europe/Helsinki")]
public sealed class CleanupJob : IJob
{
public ValueTask Execute(IJobExecutionContext context, CancellationToken cancellationToken = default)
{
return default;
}
}
Remarks
The expression is read at build time with the parser that reads it at run time, so one that
cannot parse is QZ0001 rather than an exception while the host starts. H is
resolved against the trigger's key, exactly as it is for
WithCronSchedule — see cron expressions.
This attribute says nothing on a class that does not also carry
QuartzJobAttribute, and the generator reports QZ1003 rather than letting a
schedule be declared and silently ignored.
What it cannot say — a start or end time, a calendar, job data, a retry policy, a preferred node
— is what AddTrigger<T> is for, and the two live together: a declared job can be
given further triggers by hand.
- See Also
Properties
ConfigurationKey
A configuration key whose value, when it is set, is the cron expression the trigger fires on instead of CronExpression. Defaults to none: the schedule is the attribute's.
public string? ConfigurationKey { get; init; }
Property Value
Remarks
Read from the container's IConfiguration as the scheduler is built, so
"Jobs:Cleanup:Cron" is the Cron value of the Jobs:Cleanup section, or the
environment variable Jobs__Cleanup__Cron. The constructor's expression stays required: it
is checked at build time like any other, and it is the schedule wherever the key is not set or
no IConfiguration is registered.
A configured value is not checked at build time. It is parsed as the scheduler is built, so one that does not parse, an empty one included, stops the host from starting with the parser's message rather than leaving a schedule that never fires.
A configured value of exactly - switches the trigger off: it is not scheduled, and one a
persistent store already holds under its key is unscheduled as the scheduler starts.
CronExpression
The cron expression the trigger fires on.
public string CronExpression { get; }
Property Value
Description
What the schedule is for, carried on the trigger. Defaults to none.
public string? Description { get; init; }
Property Value
ExecutionGroup
The execution group the firing counts against, for a deployment that caps how many of a kind run at once. Defaults to none.
public string? ExecutionGroup { get; init; }
Property Value
Group
The trigger key's group. Defaults to the job's group.
public string? Group { get; init; }
Property Value
MisfireInstruction
What the trigger should do about a firing it missed. Left out, the scheduler's DefaultMisfireHandling decides, which is SmartPolicy unless configured otherwise; written, it is stated, SmartPolicy included, and the default leaves it alone.
public CronTriggerMisfireInstruction MisfireInstruction { get; init; }
Property Value
MisfireThreshold
How late the trigger may fire before it counts as misfired, as a TimeSpan in its
invariant form — "00:05:00" is five minutes. Defaults to none: the job store's own
threshold.
public string? MisfireThreshold { get; init; }
Property Value
Remarks
A string, because TimeSpan is not something an attribute argument can be, parsed as
SimpleTriggerAttribute parses its interval. Read at build time: one that is not
longer than zero in whole milliseconds is QZ0008.
Exceptions
- ArgumentException
The value is not such a TimeSpan.
Name
The trigger key's name. Defaults to the job's name, then that name with -2, -3
and so on for the second and later schedules a job declares.
public string? Name { get; init; }
Property Value
Priority
The trigger's priority, which decides who wins when two triggers want the same moment and only one worker is free. Defaults to DefaultPriority.
public int Priority { get; init; }
Property Value
TimeZone
The time zone the schedule is read in, by the id FindById(string) resolves —
an IANA id such as "Europe/Helsinki" or a Windows one such as "FLE Standard Time".
Defaults to the scheduler's DefaultTimeZone, which is the
local time zone unless it is set.
public string? TimeZone { get; init; }
Property Value
Remarks
Resolved when the registration runs rather than at build time: the build machine's zone database is not the run-time machine's, and an analyzer refusing a zone your server has would be worse than no analyzer.