Interface IJobExecutionContext
- Namespace
- Quartz
- Assembly
- Quartz.dll
A context bundle containing handles to various environment information, that is given to a JobDetail instance as it is executed, and to a ITrigger instance after the execution completes.
public interface IJobExecutionContext
- Extension Methods
Properties
Calendar
ICalendar? Calendar { get; }
Property Value
CancellationToken
Returns the cancellation token which will be cancelled when the job cancellation has been requested via Interrupt(JobKey, CancellationToken) or InterruptFireInstance(string, CancellationToken).
CancellationToken CancellationToken { get; }
Property Value
FireInstanceId
Get the unique Id that identifies this particular firing instance of the trigger that triggered this job execution. It is unique to this JobExecutionContext instance as well.
string FireInstanceId { get; }
Property Value
- string
the unique fire instance id
- See Also
FireTimeUtc
The actual time the trigger fired. For instance the scheduled time may have been 10:00:00 but the actual fire time may have been 10:00:03 if the scheduler was too busy.
DateTimeOffset FireTimeUtc { get; }
Property Value
- DateTimeOffset
Returns the fireTimeUtc.
- See Also
JobDetail
IJobDetail JobDetail { get; }
Property Value
JobInstance
Get the instance of the IJob that was created for this execution.
Note: The Job instance is not available through remote scheduler interfaces.
IJob JobInstance { get; }
Property Value
JobRunTime
How long the job has run for.
TimeSpan JobRunTime { get; }
Property Value
Remarks
Once the job has completed — or thrown — this is what the scheduler measured, from a monotonic timestamp, and it is the value IJobListeners and ITriggerListeners see. That is what the member is for.
Read while the job is still running, it is an estimate instead: the wall clock now, less FireTimeUtc. It is read from UtcNow rather than from the scheduler's TimeProvider, so under a fake clock set to another instant it is meaningless and can come out negative. The testing tutorial says more.
MergedJobDataMap
Get the convenience JobDataMap of this execution context.
JobDataMap MergedJobDataMap { get; }
Property Value
Remarks
The JobDataMap found on this object serves as a convenience - it is a merge of the JobDataMap found on the JobDetail and the one found on the ITrigger, with the value in the latter overriding any same-named values in the former. It is thus considered a 'best practice' that the Execute code of a Job retrieve data from the JobDataMap found on this object.
Writing to it is safe, and it is this firing's own channel. The map is built once per firing by copying the two it merges, so a value put into it is visible to the job, to the rest of the middleware pipeline and to the listeners for as long as the firing lasts, and is seen by nothing else. It is the only per-firing bag there is, and passing something from a middleware to a listener is what it is for.
Nothing written here is persisted. It is a copy: neither the job's nor the
trigger's stored data map is touched, and the next firing starts from the stored values again.
Data that has to outlive the firing goes into JobDetail.JobDataMap on a job marked
PersistJobDataAfterExecutionAttribute, which is what a job store writes back.
NextFireTimeUtc
Gets the next fire time.
DateTimeOffset? NextFireTimeUtc { get; }
Property Value
- DateTimeOffset?
The next fire time.
PreviousFireTimeUtc
Gets the previous fire time.
DateTimeOffset? PreviousFireTimeUtc { get; }
Property Value
- DateTimeOffset?
The previous fire time.
Recovering
bool Recovering { get; }
Property Value
RecoveringTriggerKey
Returns the TriggerKey of the originally scheduled and now recovering job.
TriggerKey? RecoveringTriggerKey { get; }
Property Value
Remarks
When recovering a previously failed job execution this property returns the identity of the originally firing trigger. This recovering job will have been scheduled for the same firing time as the original job, and so is available via the ScheduledFireTimeUtc property. The original firing time of the job can be accessed via the FailedJobOriginalTriggerFireTime element of this job's JobDataMap.
RefireCount
Gets the refire count.
int RefireCount { get; }
Property Value
- int
The refire count.
Result
Returns the result (if any) that the IJob set before its execution completed (the type of object set as the result is entirely up to the particular job).
object? Result { get; set; }
Property Value
Remarks
The result itself is meaningless to Quartz, but may be informative to IJobListeners or ITriggerListeners that are watching the job's execution.
Set the result (if any) of the IJob's execution (the type of object set as the result is entirely up to the particular job).
The result itself is meaningless to Quartz, but may be informative to IJobListeners or ITriggerListeners that are watching the job's execution.
It stays object: a job writes it and a listener reads it, and the two agree on the type between themselves. Quartz cannot name that type without making IJobExecutionContext generic, which would type the whole scheduling API for the sake of a value it never looks at.
RetryAttempt
How many times this occurrence has already been retried under the trigger's
RetryPolicy: 0 on a regular fire, n on the n-th
retry.
int RetryAttempt { get; }
Property Value
Remarks
Distinct from RefireCount, which counts iterations of the in-process refire loop within a single firing — same context, same thread, nothing persisted. A retry is a fresh firing at a later instant, recorded in the job store, and it releases the execution slot while it waits.
0 for every trigger with no retry policy, which is the default.
- See Also
ScheduledFireTimeUtc
The scheduled time the trigger fired for. For instance the scheduled time may have been 10:00:00 but the actual fire time may have been 10:00:03 if the scheduler was too busy.
DateTimeOffset? ScheduledFireTimeUtc { get; }
Property Value
- DateTimeOffset?
Returns the scheduledFireTimeUtc.
- See Also
Scheduler
Get a handle to the IScheduler instance that fired the IJob.
IScheduler Scheduler { get; }
Property Value
Trigger
ITrigger Trigger { get; }