Table of Contents

Class SchedulerJobExtensions

Namespace
Quartz
Assembly
Quartz.dll

Scheduling a job by its type, the way the container-configured builder does.

public static class SchedulerJobExtensions
Inheritance
SchedulerJobExtensions
Inherited Members

Remarks

Extensions rather than IScheduler members: they compose JobBuilder, TriggerBuilder and the scheduler's own operations, and need nothing an implementation could do better, so every scheduler — including one written outside this repository — gets them without having to write them.

Methods

ScheduleJob<TJob>(IScheduler, ITrigger, Action<IJobConfigurator<TJob>>?, CancellationToken)

Schedule a job of the given type with the given trigger, building the IJobDetail along the way.

public static ValueTask<DateTimeOffset> ScheduleJob<TJob>(this IScheduler scheduler, ITrigger trigger, Action<IJobConfigurator<TJob>>? configure = null, CancellationToken cancellationToken = default) where TJob : IJob

Parameters

scheduler IScheduler

the scheduler to schedule the job with.

trigger ITrigger

the trigger that fires the job.

configure Action<IJobConfigurator<TJob>>

configures the job; omit to take everything from the type and the trigger.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask<DateTimeOffset>

the first time at which the trigger will fire.

Type Parameters

TJob

the type of the job to schedule.

Remarks

The imperative twin of q.ScheduleJob<TJob>(...) on IQuartzBuilder, so that scheduling a job at run time reads like declaring one at start-up and neither has to name a JobBuilder.

The job's identity is the first of these that exists: the one configure gave it, the one trigger already points at through JobKey, or the trigger's own key. Naming neither is therefore enough to schedule the pair, and a trigger built with ForJob still gets the job it asked for.

ScheduleJob<TJob, TInput>(IScheduler, TInput, Continuation, OneOffJobOptions, CancellationToken)

Schedules one firing of TJob with the given payload, at the given time.

public static ValueTask<ScheduledOneOffJob> ScheduleJob<TJob, TInput>(this IScheduler scheduler, TInput input, Continuation after, OneOffJobOptions options = default, CancellationToken cancellationToken = default) where TJob : IJob<TInput>

Parameters

scheduler IScheduler

The scheduler to schedule on.

input TInput

The payload the firing carries, put on the trigger.

after Continuation

The trigger whose firing this one waits for, and the outcomes of it that release the wait. After(TriggerKey, ContinuationCondition) builds one; TriggerKey is the handle an earlier call answered with.

options OneOffJobOptions

The trigger's identity and the rest of what can be said about one firing.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask<ScheduledOneOffJob>

The trigger that was stored, and the time it would first fire were it released now.

Type Parameters

TJob
TInput

Remarks

The firing is stored in Awaiting and never acquired until the parent's completion settles it, inside the parent's own lock and transaction. An outcome the condition names releases it; any other outcome deletes it.

There is no time argument, because the time is the parent's completion. Give OneOffJobOptions nothing else and the firing happens as soon as it is released; a floor — "and never before nine" — is a StartAfter trigger built by hand.

The parent has to be in the store when this is called: a one-shot parent is deleted once it has fired, so schedule the continuation before the parent can finish — the handle an earlier call answered with is the one to use straight away — or check the parent's key.

Exceptions

ObjectDoesNotExistException

The parent after names is not in the store. Nothing is stored.

ScheduleJob<TJob, TInput>(IScheduler, TInput, DateTimeOffset, OneOffJobOptions, CancellationToken)

Schedules one firing of TJob with the given payload, at the given time.

public static ValueTask<ScheduledOneOffJob> ScheduleJob<TJob, TInput>(this IScheduler scheduler, TInput input, DateTimeOffset at, OneOffJobOptions options = default, CancellationToken cancellationToken = default) where TJob : IJob<TInput>

Parameters

scheduler IScheduler

The scheduler to schedule on.

input TInput

The payload the firing carries, put on the trigger.

at DateTimeOffset

When the job should run.

options OneOffJobOptions

The trigger's identity and the rest of what can be said about one firing.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask<ScheduledOneOffJob>

The trigger that was stored and the time it will first fire.

Type Parameters

TJob

The job to fire.

TInput

The payload's type, inferred from input.

ScheduleJob<TJob, TInput>(IScheduler, TInput, TimeSpan, OneOffJobOptions, CancellationToken)

Schedules one firing of TJob with the given payload, at the given time.

public static ValueTask<ScheduledOneOffJob> ScheduleJob<TJob, TInput>(this IScheduler scheduler, TInput input, TimeSpan delay, OneOffJobOptions options = default, CancellationToken cancellationToken = default) where TJob : IJob<TInput>

Parameters

scheduler IScheduler

The scheduler to schedule on.

input TInput

The payload the firing carries, put on the trigger.

delay TimeSpan

How long from now the job should run.

options OneOffJobOptions

The trigger's identity and the rest of what can be said about one firing.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask<ScheduledOneOffJob>

Type Parameters

TJob
TInput

Remarks

"Now" is TimeProvider, so a delay is measured against the same clock the scheduling loop will compare it to.

TriggerJob(IScheduler, JobKey, CancellationToken)

Fires the stored job now with no data of its own: TriggerJob(JobKey, JobDataMap?, CancellationToken) with the token as the second argument.

public static ValueTask TriggerJob(this IScheduler scheduler, JobKey jobKey, CancellationToken cancellationToken = default)

Parameters

scheduler IScheduler

The scheduler to fire the job on.

jobKey JobKey

The stored job to fire.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask

Remarks

The interface member's second parameter is a JobDataMap, so TriggerJob(jobKey, token) does not bind to it. Without this overload it would bind to TriggerJob<TInput>(IScheduler, JobKey, TInput, CancellationToken), the token as the input. A non-generic overload is preferred over a generic one, so the call means what it reads as.

A JobDataMap, or null, as the second argument still binds to the interface member, which an instance member always wins.

Exceptions

ArgumentNullException

scheduler or jobKey is null.

SchedulerException

The scheduler has been shut down.

JobPersistenceException

No job is stored under jobKey.

TriggerJob<TInput>(IScheduler, JobKey, TInput, CancellationToken)

Fires the stored job now with the given input, and returns the key of the trigger that fires it.

public static ValueTask<TriggerKey> TriggerJob<TInput>(this IScheduler scheduler, JobKey jobKey, TInput input, CancellationToken cancellationToken = default)

Parameters

scheduler IScheduler

The scheduler to fire the job on.

jobKey JobKey

The stored job to fire.

input TInput

The payload the firing carries, put on the trigger.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask<TriggerKey>

The key of the manual firing's trigger.

Type Parameters

TInput

The input's type, inferred from input.

Remarks

The typed twin of TriggerJob(JobKey, JobDataMap?, CancellationToken), and the same firing: a one-shot trigger named MT_ and a number in the default group, marked with ManualTrigger so history and the dashboard show a manual run, and in the execution group TriggerJob would give it. The input goes under JobInput, where UsingInput puts it, and the scheduler's IJobInputSerializer writes it as the trigger is stored, so an IJob<TInput> receives it as its parameter.

The trigger is stored with ScheduleJob(ITrigger, ScheduleJobOptions, CancellationToken), so its key is known before it can fire. Look the run up with it: Trigger in the execution history, or TriggerName while it runs.

Trimmed or native AOT: declare TInput with AddJsonTypeInfoResolver(IQuartzBuilder, IJsonTypeInfoResolver), as for UsingInput; the store serializer's own registry does not reach the input serializer. Nothing here reflects.

Over HttpScheduler the input crosses the wire as a job data value, before any input serializer sees it, so it has to be a string or a job data value type. Pass a structured payload as the string the host's serializer reads: JSON, for the default one. The execution group is resolved by the calling process, which skips a job type it cannot load.

Exceptions

ArgumentNullException

scheduler or jobKey is null.

ArgumentException

input is a CancellationToken, which only an explicit TriggerJob<CancellationToken>(…) can pass: TriggerJob(jobKey, token) binds to TriggerJob(IScheduler, JobKey, CancellationToken).

SchedulerException

The scheduler has been shut down.

JobPersistenceException

No job is stored under jobKey.