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
schedulerISchedulerthe scheduler to schedule the job with.
triggerITriggerthe trigger that fires the job.
configureAction<IJobConfigurator<TJob>>configures the job; omit to take everything from the type and the trigger.
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
- ValueTask<DateTimeOffset>
the first time at which the trigger will fire.
Type Parameters
TJobthe 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
schedulerISchedulerThe scheduler to schedule on.
inputTInputThe payload the firing carries, put on the trigger.
afterContinuationThe 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.
optionsOneOffJobOptionsThe trigger's identity and the rest of what can be said about one firing.
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
- ValueTask<ScheduledOneOffJob>
The trigger that was stored, and the time it would first fire were it released now.
Type Parameters
TJobTInput
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
afternames 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
schedulerISchedulerThe scheduler to schedule on.
inputTInputThe payload the firing carries, put on the trigger.
atDateTimeOffsetWhen the job should run.
optionsOneOffJobOptionsThe trigger's identity and the rest of what can be said about one firing.
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
- ValueTask<ScheduledOneOffJob>
The trigger that was stored and the time it will first fire.
Type Parameters
TJobThe job to fire.
TInputThe 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
schedulerISchedulerThe scheduler to schedule on.
inputTInputThe payload the firing carries, put on the trigger.
delayTimeSpanHow long from now the job should run.
optionsOneOffJobOptionsThe trigger's identity and the rest of what can be said about one firing.
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
Type Parameters
TJobTInput
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
schedulerISchedulerThe scheduler to fire the job on.
jobKeyJobKeyThe stored job to fire.
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
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
schedulerorjobKeyis 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
schedulerISchedulerThe scheduler to fire the job on.
jobKeyJobKeyThe stored job to fire.
inputTInputThe payload the firing carries, put on the trigger.
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
- ValueTask<TriggerKey>
The key of the manual firing's trigger.
Type Parameters
TInputThe 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
schedulerorjobKeyis null.- ArgumentException
inputis a CancellationToken, which only an explicitTriggerJob<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.