Table of Contents

Class SimpleJobFactory

Namespace
Quartz.Impl
Assembly
Quartz.dll

The default JobFactory used by Quartz - simply activates the job class through its public parameterless constructor.

public class SimpleJobFactory : IJobFactory
Inheritance
SimpleJobFactory
Implements
Derived
Inherited Members

Constructors

SimpleJobFactory(ILoggerFactory?)

public SimpleJobFactory(ILoggerFactory? loggerFactory = null)

Parameters

loggerFactory ILoggerFactory

Where this factory and its derived types create their loggers. A factory the container builds is handed the application's; one constructed by hand — UseJobFactory(instance) — is handed nothing and reads LogProvider, as before. A factory rather than a logger, because PropertySettingJobFactory logs under its own category and has to be able to pass the same source down.

Methods

CreateJob(TriggerFiredBundle, IScheduler, CancellationToken)

Called by the scheduler at the time of the trigger firing, in order to produce a IJob instance on which to call Execute.

public virtual ValueTask<JobScope> CreateJob(TriggerFiredBundle bundle, IScheduler scheduler, CancellationToken cancellationToken = default)

Parameters

bundle TriggerFiredBundle

The TriggerFiredBundle from which the IJobDetail and other info relating to the trigger firing can be obtained.

scheduler IScheduler

The scheduler the job will run under, made available to the job through its execution context.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask<JobScope>

the newly instantiated job, together with any per-fire state, in a JobScope

Remarks

It should be extremely rare for this method to throw an exception - basically only the case where there is no way at all to instantiate and prepare the Job for execution. When the exception is thrown, the Scheduler will move all triggers associated with the Job into the Error state, which will require human intervention (e.g. an application restart after fixing whatever configuration problem led to the issue with instantiating the Job).

Exceptions

SchedulerException

The job could not be instantiated.

DisposeIfDisposable(object?, CancellationToken)

Disposes target if it is disposable, preferring IAsyncDisposable over IDisposable. Anything else is left alone.

protected static ValueTask DisposeIfDisposable(object? target, CancellationToken cancellationToken = default)

Parameters

target object
cancellationToken CancellationToken

Returns

ValueTask

InstantiateJobCore(TriggerFiredBundle)

Synchronous core of CreateJob(TriggerFiredBundle, IScheduler, CancellationToken) that derived classes can call when they need a job instance without driving the asynchronous code path.

protected IJob InstantiateJobCore(TriggerFiredBundle bundle)

Parameters

bundle TriggerFiredBundle

Returns

IJob

ReturnJob(JobScope, CancellationToken)

Allows the job factory to destroy/cleanup the job once it has finished executing.

public virtual ValueTask ReturnJob(JobScope scope, CancellationToken cancellationToken = default)

Parameters

scope JobScope
cancellationToken CancellationToken

Returns

ValueTask

Remarks

Disposes the job, then any state the factory attached to the scope, preferring IAsyncDisposable over IDisposable for each. Anything that is neither is left alone. The state is disposed even when disposing the job throws, since whatever the factory had to allocate is usually the more expensive thing to leak.

See Also