Class JobBuilder<TJob>
- Namespace
- Quartz
- Assembly
- Quartz.dll
JobBuilder is used to instantiate IJobDetails for a known job type.
public sealed class JobBuilder<TJob> : IJobConfigurator<TJob> where TJob : IJob
Type Parameters
TJob
- Inheritance
-
JobBuilder<TJob>
- Implements
-
IJobConfigurator<TJob>
- Inherited Members
- Extension Methods
Remarks
Knowing the job type is what lets UsingJobData<TValue>(Expression<Func<TJob, TValue>>, TValue) take the job's property instead of
its key. JobBuilder.Create() gives a builder for IJob, which has no properties to
name; JobBuilder.Create<TJob>() gives one that does.
Properties
Key
The key that identifies the job uniquely, or null when none was set.
public JobKey? Key { get; }
Property Value
Remarks
Readable so that code building a job and something that has to agree with it — a trigger, a
registration — can tell an identity the caller chose from the one Build() would
generate. Reading it after Build still reports what the builder was told, not what was
generated.
Methods
Build()
Produce the IJobDetail instance defined by this JobBuilder.
public IJobDetail Build()
Returns
- IJobDetail
the defined JobDetail.
DisallowConcurrentExecution(bool)
Instructs the IScheduler whether or not concurrent execution of the job should be disallowed.
public JobBuilder<TJob> DisallowConcurrentExecution(bool concurrentExecutionDisallowed = true)
Parameters
concurrentExecutionDisallowedboolIndicates whether or not concurrent execution of the job should be disallowed.
Returns
- JobBuilder<TJob>
The updated JobBuilder.
Remarks
If not explicitly set, concurrent execution of a job is only disallowed it either the JobType itself, one of its ancestors or one of the interfaces that it implements, is annotated with DisallowConcurrentExecutionAttribute.
- See Also
OfType(JobType)
Set the job type to one that already knows how to resolve the name it carries.
public JobBuilder<TJob> OfType(JobType jobType)
Parameters
jobTypeJobTypethe job type, with whatever resolution it was constructed with
Returns
- JobBuilder<TJob>
the updated JobBuilder
Remarks
A name read back out of a job store may be spelled the way an older Quartz wrote it, and only the scheduler's type loader knows what such a spelling means today. Handing the resolution over rather than the resolved type keeps the stored name as it was stored.
This is also where a bare name goes: OfType((JobType) name). There is deliberately no
OfType(string), because the cast is explicit precisely so that
accepting an unvalidated name — one whose resolution is deferred to the first use of
Type, and whose failure surfaces there — is visible at the call that made
the leap.
OfType(Type)
Set the class which will be instantiated and executed when a Trigger fires that is associated with this JobDetail.
public JobBuilder<TJob> OfType(Type type)
Parameters
typeType
Returns
- JobBuilder<TJob>
the updated JobBuilder
- See Also
OfType<T>()
Set the class which will be instantiated and executed when a Trigger fires that is associated with this JobDetail.
public JobBuilder<TJob> OfType<T>() where T : TJob
Returns
- JobBuilder<TJob>
the updated JobBuilder
Type Parameters
T
- See Also
PersistJobDataAfterExecution(bool)
Instructs the IScheduler whether or not job data should be re-stored when execution of the job completes.
public JobBuilder<TJob> PersistJobDataAfterExecution(bool persistJobDataAfterExecution = true)
Parameters
persistJobDataAfterExecutionboolIndicates whether or not job data should be re-stored when execution of the job completes.
Returns
- JobBuilder<TJob>
The updated JobBuilder.
Remarks
If not explicitly set, job data is only re-stored it either the JobType itself, one of its ancestors or one of the interfaces that it implements, is annotated with PersistJobDataAfterExecutionAttribute.
- See Also
RequestRecovery(bool)
Instructs the IScheduler whether or not the job should be re-executed if a 'recovery' or 'fail-over' situation is encountered.
public JobBuilder<TJob> RequestRecovery(bool shouldRecover = true)
Parameters
shouldRecoverbool
Returns
- JobBuilder<TJob>
the updated JobBuilder
Remarks
If not explicitly set, the default value is false.
StoreDurably(bool)
Whether or not the job should remain stored after it is orphaned (no ITriggers point to it).
public JobBuilder<TJob> StoreDurably(bool durability = true)
Parameters
durabilityboolthe value to set for the durability property.
Returns
- JobBuilder<TJob>
the updated JobBuilder
Remarks
If not explicitly set, the default value is false.
- See Also
UsingJobData(JobDataMap)
Add all the data from the given JobDataMap to the IJobDetail's JobDataMap.
public JobBuilder<TJob> UsingJobData(JobDataMap newJobDataMap)
Parameters
newJobDataMapJobDataMap
Returns
- JobBuilder<TJob>
the updated JobBuilder
- See Also
UsingJobData(string, object?)
Add the given key-value pair to the JobDetail's JobDataMap.
public JobBuilder<TJob> UsingJobData(string key, object? value)
Parameters
Returns
- JobBuilder<TJob>
the updated JobBuilder
Remarks
The value is stored as given. A persistent job store can only hold what its serializer
round-trips, and AdoJobStore's StoreJobDataAsStrings mode only strings.
- See Also
UsingJobData<TValue>(Expression<Func<TJob, TValue>>, TValue)
Add a value to the JobDetail's JobDataMap under the name of the job property it is meant to end up on.
public JobBuilder<TJob> UsingJobData<TValue>(Expression<Func<TJob, TValue>> jobProperty, TValue value)
Parameters
jobPropertyExpression<Func<TJob, TValue>>an expression naming the job property, such as
job => job.ParametervalueTValuethe value to bind to that property
Returns
- JobBuilder<TJob>
the updated JobBuilder
Type Parameters
TValue
Remarks
The property is named rather than spelled, so the key cannot be mistyped and the value cannot be of the wrong type. It has to be a public settable property read directly off the job - a path through another property has nowhere to land, since the job factory sets properties on the job instance itself - and it is rejected here rather than dropped silently when the job runs. Properties inherited from a base job are fine.
The value is stored in the property's own type, so an implicit widening at the call site is undone and a value that does not fit is rejected here. An enum property takes the enum's name.
The same care applies as to any other job data: a persistent job store can only hold what its
serializer round-trips, and AdoJobStore's StoreJobDataAsStrings mode only strings. Nothing beyond
enums is converted for you.
- See Also
WithDescription(string?)
Set the given (human-meaningful) description of the Job.
public JobBuilder<TJob> WithDescription(string? description)
Parameters
descriptionstringthe description for the Job
Returns
- JobBuilder<TJob>
the updated JobBuilder
- See Also
WithIdentity(JobKey)
Use a JobKey to identify the JobDetail.
public JobBuilder<TJob> WithIdentity(JobKey key)
Parameters
keyJobKeythe Job's JobKey
Returns
- JobBuilder<TJob>
the updated JobBuilder
Remarks
If none of the 'withIdentity' methods are set on the JobBuilder, then a random, unique JobKey will be generated.
- See Also
WithIdentity(string)
Use a JobKey with the given name and default group to identify the JobDetail.
public JobBuilder<TJob> WithIdentity(string name)
Parameters
namestringthe name element for the Job's JobKey
Returns
- JobBuilder<TJob>
the updated JobBuilder
Remarks
If none of the 'withIdentity' methods are set on the JobBuilder, then a random, unique JobKey will be generated.
- See Also
WithIdentity(string, string)
Use a JobKey with the given name and group to identify the JobDetail.
public JobBuilder<TJob> WithIdentity(string name, string group)
Parameters
namestringthe name element for the Job's JobKey
groupstringthe group element for the Job's JobKey
Returns
- JobBuilder<TJob>
the updated JobBuilder
Remarks
If none of the 'withIdentity' methods are set on the JobBuilder, then a random, unique JobKey will be generated.
- See Also