Table of Contents

Class SimpleTriggerAttribute

Namespace
Quartz
Assembly
Quartz.dll

A fixed-interval schedule for the job this class declares with QuartzJobAttribute. Write it as many times as the job has schedules, beside any CronTriggerAttribute; the generator emits one AddTrigger<T> call per attribute.

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public sealed class SimpleTriggerAttribute : Attribute
Inheritance
SimpleTriggerAttribute
Inherited Members

Examples

[QuartzJob]
[SimpleTrigger("00:10:00")]
[SimpleTrigger("00:00:05", Name = "warm-up", RepeatCount = 3)]
public sealed class PollInboxJob : IJob
{
    public ValueTask Execute(IJobExecutionContext context, CancellationToken cancellationToken = default)
    {
        return default;
    }
}

Remarks

The trigger starts when the scheduler is built, as any AddTrigger<T> without StartAt does: it fires as the scheduler starts, then once per interval.

The interval is read at build time. One that is not a positive TimeSpan, and a RepeatCount below -1, are QZ0005 rather than an exception while the host starts, and the generated registration carries the interval as ticks, so nothing parses it at run time.

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.

Constructors

SimpleTriggerAttribute(string)

Declares the interval as a TimeSpan in its invariant form — "00:10:00" is ten minutes, "1.00:00:00" is a day.

public SimpleTriggerAttribute(string interval)

Parameters

interval string

The time between firings, as a positive invariant TimeSpan.

Remarks

A string, because TimeSpan is not something an attribute argument can be. The format is Parse(string, IFormatProvider)'s, parsed with the invariant culture, as JobTimeoutAttribute's is.

Exceptions

ArgumentNullException

interval is null.

ArgumentException

interval is not a TimeSpan.

ArgumentOutOfRangeException

interval is zero or negative.

Properties

ConfigurationKey

A configuration key whose value, when it is set, is the interval the trigger fires on instead of Interval. Defaults to none: the schedule is the attribute's.

public string? ConfigurationKey { get; init; }

Property Value

string

Remarks

Read from the container's IConfiguration as the scheduler is built, so "Jobs:Poll:Interval" is the Interval value of the Jobs:Poll section, or the environment variable Jobs__Poll__Interval. The constructor's interval stays required: it is checked at build time, and it is the schedule wherever the key is not set or no IConfiguration is registered. Only the interval is read; RepeatCount and the rest stay the attribute's.

A configured value is not checked at build time. One that is not a positive invariant TimeSpan, an empty one included, stops the host from starting with a FormatException naming the key, 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.

Description

What the schedule is for, carried on the trigger. Defaults to none.

public string? Description { get; init; }

Property Value

string

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

string

Group

The trigger key's group. Defaults to the job's group.

public string? Group { get; init; }

Property Value

string

Interval

The time between firings.

public TimeSpan Interval { get; }

Property Value

TimeSpan

MeasureIntervalFromCompletion

Whether the interval is measured from the previous run's completion rather than from its scheduled time: a fixed delay. Defaults to false, a fixed rate.

public bool MeasureIntervalFromCompletion { get; init; }

Property Value

bool

Remarks

The trigger then never overlaps itself. Every node of a cluster must be 4.7 or later.

See Also

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 SimpleTriggerMisfireInstruction MisfireInstruction { get; init; }

Property Value

SimpleTriggerMisfireInstruction

MisfireThreshold

How late the trigger may fire before it counts as misfired, as a TimeSpan in its invariant form, as the interval is — "00:05:00" is five minutes. Defaults to none: the job store's own threshold.

public string? MisfireThreshold { get; init; }

Property Value

string

Remarks

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, CronTriggerAttribute included.

public string? Name { get; init; }

Property Value

string

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

int

RepeatCount

How many times the trigger repeats after its first firing, so the total number of firings is one more than this. Defaults to RepeatIndefinitely, -1, which repeats forever.

public int RepeatCount { get; init; }

Property Value

int

Exceptions

ArgumentOutOfRangeException

The value is below -1.

See Also