Class SimpleJobFactory
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
loggerFactoryILoggerFactoryWhere 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
bundleTriggerFiredBundleThe TriggerFiredBundle from which the IJobDetail and other info relating to the trigger firing can be obtained.
schedulerISchedulerThe scheduler the job will run under, made available to the job through its execution context.
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
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
targetobjectcancellationTokenCancellationToken
Returns
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
bundleTriggerFiredBundle
Returns
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
scopeJobScopecancellationTokenCancellationToken
Returns
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.