Table of Contents

Class TriggerBuilder<TJob>

Namespace
Quartz
Assembly
Quartz.dll

TriggerBuilder is used to instantiate ITriggers for a trigger that fires a known job type.

public sealed class TriggerBuilder<TJob> : ITriggerConfigurator<TJob>, ITriggerConfigurator where TJob : IJob

Type Parameters

TJob
Inheritance
TriggerBuilder<TJob>
Implements
Inherited Members
Extension Methods

Remarks

Knowing the job type is what lets UsingJobData<TValue>(Expression<Func<TJob, TValue>>, TValue) take the job's property instead of its key. TriggerBuilder.Create() gives a builder for IJob, which has no properties to name; TriggerBuilder.Create<TJob>() gives one that does.

Properties

Key

The key that identifies the trigger uniquely, or null when none was set.

public TriggerKey? Key { get; }

Property Value

TriggerKey

Remarks

Readable so that code building a trigger and something that has to agree with it — a job, a registration — can tell an identity the caller chose from the one Build() would generate. Unlike Key, reading it after Build reports a generated key too: Build keeps the key it generated, so building the same builder twice produces the same trigger rather than two.

Methods

Build()

Produce the ITrigger.

public ITrigger Build()

Returns

ITrigger

a Trigger that meets the specifications of the builder.

Remarks

The builder can be built more than once and answers with the same identity each time: a key it generated is kept rather than generated afresh, so two builds of one builder are the same trigger twice rather than two triggers. Any H token in a cron schedule is resolved here, from that identity, which is why it has to be settled first.

EndAt(DateTimeOffset?)

Set the time at which the Trigger will no longer fire - even if it's schedule has remaining repeats.

public TriggerBuilder<TJob> EndAt(DateTimeOffset? endTimeUtc)

Parameters

endTimeUtc DateTimeOffset?

the end time for the Trigger. If null, the end time is indefinite.

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

Remarks

The end time is inclusive: it is the last instant at which the trigger may fire, so a fire time that lands exactly on it is one the trigger fires.

See Also

ForJob(IJobDetail)

Set the identity of the Job which should be fired by the produced Trigger, by extracting the JobKey from the given job.

public TriggerBuilder<TJob> ForJob(IJobDetail jobDetail)

Parameters

jobDetail IJobDetail

the Job to fire.

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

ForJob(JobKey)

Set the identity of the Job which should be fired by the produced Trigger.

public TriggerBuilder<TJob> ForJob(JobKey jobKey)

Parameters

jobKey JobKey

the identity of the Job to fire.

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

ForJob(string)

Set the identity of the Job which should be fired by the produced Trigger - a JobKey will be produced with the given name and default group.

public TriggerBuilder<TJob> ForJob(string jobName)

Parameters

jobName string

the name of the job (in default group) to fire.

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

ForJob(string, string)

Set the identity of the Job which should be fired by the produced Trigger - a JobKey will be produced with the given name and group.

public TriggerBuilder<TJob> ForJob(string jobName, string jobGroup)

Parameters

jobName string

the name of the job to fire.

jobGroup string

the group of the job to fire.

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

StartAt(DateTimeOffset)

Set the time the Trigger should start at - the trigger may or may not fire at this time - depending upon the schedule configured for the Trigger. However the Trigger will NOT fire before this time, regardless of the Trigger's schedule.

public TriggerBuilder<TJob> StartAt(DateTimeOffset startTimeUtc)

Parameters

startTimeUtc DateTimeOffset

the start time for the Trigger.

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

StartNow()

Set the time the Trigger should start at to the current moment - the trigger may or may not fire at this time - depending upon the schedule configured for the Trigger.

public TriggerBuilder<TJob> StartNow()

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

UsingJobData(JobDataMap)

Add the given key-value pair to the Trigger's JobDataMap.

public TriggerBuilder<TJob> UsingJobData(JobDataMap newJobDataMap)

Parameters

newJobDataMap JobDataMap

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

UsingJobData(string, object?)

Add the given key-value pair to the Trigger's JobDataMap.

public TriggerBuilder<TJob> UsingJobData(string key, object? value)

Parameters

key string

the key to store the value under

value object

the value to store

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

Remarks

The value is stored as given. A persistent job store can only hold what its serializer round-trips, and AdoJobStore's UseProperties mode only strings.

See Also

UsingJobData<TValue>(Expression<Func<TJob, TValue>>, TValue)

Add a value to the Trigger's JobDataMap under the name of the job property it is meant to end up on.

public TriggerBuilder<TJob> UsingJobData<TValue>(Expression<Func<TJob, TValue>> jobProperty, TValue value)

Parameters

jobProperty Expression<Func<TJob, TValue>>

an expression naming the job property, such as job => job.Parameter

value TValue

the value to bind to that property

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

Type Parameters

TValue

Remarks

This is how one job is given different inputs per trigger without spelling its property names: trigger data overrides job data in the map the job finally sees.

It has to be a public settable property read directly off the job - a path through another property has nowhere to land, since the job factory sets properties on the job instance itself. Properties inherited from a base job are fine. Whether the property belongs to the job this trigger actually fires can only be checked when the trigger was pointed at the job with ForJob(IJobDetail) and that job's type resolves; pointed at a key, or at a job named by a type this process cannot load, the job type only names the properties.

The value is stored in the property's own type, so an implicit widening at the call site is undone and a value that does not fit is rejected here. An enum property takes the enum's name.

The same care applies as to any other job data: a persistent job store can only hold what its serializer round-trips, and AdoJobStore's UseProperties mode only strings. Nothing beyond enums is converted for you.

See Also

WithCalendarName(string?)

Set the name of the ICalendar that should be applied to this Trigger's schedule.

public TriggerBuilder<TJob> WithCalendarName(string? calendarName)

Parameters

calendarName string

the name of the Calendar to reference.

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

WithDescription(string?)

Set the given (human-meaningful) description of the Trigger.

public TriggerBuilder<TJob> WithDescription(string? description)

Parameters

description string

the description for the Trigger

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

WithExecutionGroup(string?)

Set the execution group for the Trigger. Execution groups allow thread limits to be configured - per node or across the cluster - so that resource-intensive jobs do not saturate all available threads.

public TriggerBuilder<TJob> WithExecutionGroup(string? executionGroup)

Parameters

executionGroup string

the execution group name, or null to clear

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

WithIdentity(TriggerKey)

Use the given TriggerKey to identify the Trigger.

public TriggerBuilder<TJob> WithIdentity(TriggerKey key)

Parameters

key TriggerKey

the TriggerKey for the Trigger to be built

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

Remarks

If none of the 'withIdentity' methods are set on the TriggerBuilder, then a random, unique TriggerKey will be generated.

See Also

WithIdentity(string)

Use a TriggerKey with the given name and default group to identify the Trigger.

public TriggerBuilder<TJob> WithIdentity(string name)

Parameters

name string

the name element for the Trigger's TriggerKey

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

Remarks

If none of the 'withIdentity' methods are set on the TriggerBuilder, then a random, unique TriggerKey will be generated.

See Also

WithIdentity(string, string)

Use a TriggerKey with the given name and group to identify the Trigger.

public TriggerBuilder<TJob> WithIdentity(string name, string group)

Parameters

name string

the name element for the Trigger's TriggerKey

group string

the group element for the Trigger's TriggerKey

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

Remarks

If none of the 'withIdentity' methods are set on the TriggerBuilder, then a random, unique TriggerKey will be generated.

See Also

WithPreferredNode(PreferredNode)

Set which cluster node the Trigger prefers to run on. When pinned, only that node executes this trigger, with automatic failover to other nodes while the preferred node is down.

public TriggerBuilder<TJob> WithPreferredNode(PreferredNode preferredNode)

Parameters

preferredNode PreferredNode

The pin: None to clear, Auto for automatic first-fire pinning, or For(string) to name a node.

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

WithPriority(int)

Set the Trigger's priority. When more than one Trigger have the same fire time, the scheduler will fire the one with the highest priority first.

public TriggerBuilder<TJob> WithPriority(int priority)

Parameters

priority int

the priority for the Trigger

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

See Also

WithRetryPolicy(RetryPolicy?)

Set how the scheduler re-fires this trigger when its job fails.

public TriggerBuilder<TJob> WithRetryPolicy(RetryPolicy? retryPolicy)

Parameters

retryPolicy RetryPolicy

the retry policy, or null for no retries

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

Remarks

A retry never displaces the trigger's next scheduled occurrence, so a policy whose waits are longer than the gap between occurrences does nothing. This is not RefireImmediately, which re-runs the job on the same thread within the same firing.

See Also

WithSchedule(IScheduleBuilder)

Set the IScheduleBuilder that will be used to define the Trigger's schedule.

public TriggerBuilder<TJob> WithSchedule(IScheduleBuilder scheduleBuilder)

Parameters

scheduleBuilder IScheduleBuilder

the schedule builder to use.

Returns

TriggerBuilder<TJob>

the updated TriggerBuilder

Remarks

The particular IScheduleBuilder used will dictate the concrete type of Trigger that is produced by the TriggerBuilder.

See Also

See Also