Class QuartzJobAttribute
- Namespace
- Quartz
- Assembly
- Quartz.dll
Declares this class as a job to register, where the job is written. The analyzer that ships inside
Quartz.nupkg generates the AddJob<T> call for it, which
builder.AddDeclaredJobs() runs.
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public sealed class QuartzJobAttribute : Attribute
- Inheritance
-
QuartzJobAttribute
- Inherited Members
Examples
[QuartzJob(Name = "cleanup", Group = "maintenance")]
[CronTrigger("0 0 0/6 * * ?")]
public sealed class CleanupJob : IJob
{
public ValueTask Execute(IJobExecutionContext context, CancellationToken cancellationToken = default)
{
return default;
}
}
Remarks
Nothing reads this attribute at run time. It is read by the compiler, and what reaches the
scheduler is ordinary generated C# calling the same AddJob<T> and
AddTrigger<T> a hand-written registration calls — so a declared job is trimmable and
native-AOT clean for the reason a hand-written one is, and everything a registration can do that
an attribute cannot say is still available beside it.
The class has to be a concrete, non-generic, accessible IJob —
IJob<TInput> counts, since it is one — or the generator reports QZ1001
rather than emitting a call that would not compile. Two declarations resolving to the same key
are QZ1002.
A declared job's schedules are CronTriggerAttribute and SimpleTriggerAttribute, one per schedule. A job declaring none is registered durably, because a job with no trigger is the shape a store discards otherwise.
Properties
Description
What the job is for, carried on the job detail. Defaults to none.
public string? Description { get; init; }
Property Value
Durable
Whether the job stays in the store when no trigger points at it.
public bool Durable { get; init; }
Property Value
Remarks
Forced on for a job that declares no CronTriggerAttribute or SimpleTriggerAttribute: a non-durable job with no trigger is deleted as soon as it is stored, so declaring one would be declaring nothing.
Group
The job key's group. Defaults to DefaultGroup.
public string? Group { get; init; }
Property Value
Name
The job key's name. Defaults to the class's own name.
public string? Name { get; init; }
Property Value
Remarks
The default is the name alone, not the namespace-qualified one: a job key is what an operator reads in a dashboard and what a scheduling file names.
RequestRecovery
Whether a firing interrupted by a hard shutdown is re-fired when this node — or another one — recovers.
public bool RequestRecovery { get; init; }
Property Value
Scheduler
Which scheduler this job belongs to, by the name it was registered under with
AddQuartz(name, …). Defaults to every scheduler AddDeclaredJobs() is called on.
public string? Scheduler { get; init; }
Property Value
Remarks
The generated registration is wrapped in a check on IQuartzBuilder.SchedulerName, so a
job naming a scheduler is skipped by every other one — the unnamed scheduler included, whose
name is the empty string.