Struct JobScope
- Namespace
- Quartz.Extensibility
- Assembly
- Quartz.dll
A job instance produced by an IJobFactory, together with whatever per-fire state the factory needs back when the job is returned.
public readonly struct JobScope
- Inherited Members
Remarks
A factory that has to allocate something in order to build the job — a dependency injection scope, a database connection, a tenant context — has nowhere to keep it between CreateJob(TriggerFiredBundle, IScheduler, CancellationToken) and ReturnJob(JobScope, CancellationToken) unless it hides it inside the job instance. State is that place, so the job stays the job.
This is a struct so that a synchronously-completed ValueTask<TResult> carries it without allocating.
Constructors
JobScope(IJob, object?)
Initializes a new JobScope.
public JobScope(IJob job, object? state = null)
Parameters
jobIJobThe job to execute.
stateobjectOptional per-fire state, handed back verbatim to ReturnJob(JobScope, CancellationToken).
Properties
Job
The job to execute.
public IJob Job { get; }
Property Value
Remarks
Always set when the scope was built with the constructor. default(JobScope) skips that
constructor and leaves this null despite the annotation, so a factory must never return
default — the scheduler rejects such a scope rather than executing it.
State
Opaque state the factory attached when it created the job.
public object? State { get; }
Property Value
Remarks
Quartz never interprets this. ReturnJob(JobScope, CancellationToken) disposes it if it happens to be IAsyncDisposable or IDisposable, which is enough for the common case; anything else is the factory's own business.