Class CronScheduleBuilder
- Namespace
- Quartz
- Assembly
- Quartz.dll
CronScheduleBuilder is a IScheduleBuilder that defines CronExpression-based schedules for ITriggers.
public sealed class CronScheduleBuilder : IScheduleBuilder
- Inheritance
-
CronScheduleBuilder
- Implements
- Inherited Members
Remarks
Quartz provides a builder-style API for constructing scheduling-related entities via a Domain-Specific Language (DSL). The DSL can best be utilized through the usage of static imports of the methods on the classes TriggerBuilder, JobBuilder, DateBuilder, JobKey, TriggerKey and the various IScheduleBuilder implementations.
Client code can then use the DSL to write code such as this:
IJobDetail job = JobBuilder.Create<MyJob>()
.WithIdentity("myJob")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("myTrigger", "myTriggerGroup")
.WithCronSchedule("0 0/5 * * * ?")
.Build();
await scheduler.ScheduleJob(job, trigger);
For schedules that are easier to describe than to spell as a cron string, build the expression with CronExpressionBuilder and pass it to Create(CronExpression).
Methods
Build()
Build the actual Trigger -- NOT intended to be invoked by end users, but will rather be invoked by a TriggerBuilder which this ScheduleBuilder is given to.
public IMutableTrigger Build()
Returns
- See Also
Create(CronExpression)
Create a CronScheduleBuilder with the given cron-expression.
public static CronScheduleBuilder Create(CronExpression cronExpression)
Parameters
cronExpressionCronExpressionthe cron expression to base the schedule on.
Returns
- CronScheduleBuilder
the new CronScheduleBuilder
Remarks
This is also the way to resolve H (hash) tokens against something other than the
trigger's own key: Create(CronExpression.ParseWithHash(expression, hashKey)).
- See Also
Create(string)
Create a CronScheduleBuilder from a cron expression written in the Quartz format.
public static CronScheduleBuilder Create(string cronExpression)
Parameters
cronExpressionstringthe cron expression to base the schedule on.
Returns
- CronScheduleBuilder
the new CronScheduleBuilder
Remarks
The expression is parsed here rather than at Build(), so a malformed one is refused by the call that named it.
Exceptions
- ArgumentNullException
cronExpressionis null.- FormatException
cronExpressionis not a valid cron expression.
- See Also
Create(string, CronFormat)
Create a CronScheduleBuilder from an expression written in the given format.
public static CronScheduleBuilder Create(string cronExpression, CronFormat format)
Parameters
cronExpressionstringthe cron expression to base the schedule on.
formatCronFormatthe dialect
cronExpressionis written in.
Returns
- CronScheduleBuilder
the new CronScheduleBuilder
Remarks
Unix reads the five-field crontab form. What the schedule holds
afterwards is the canonical Quartz expression that says the same thing, so a trigger built from
"30 4 * * 1" stores and displays "0 30 4 ? * MON".
There is no WithCronSchedule overload taking a format; compose one from the expression
instead: WithCronSchedule(CronExpression.Parse(s, CronFormat.Unix)).
Exceptions
- ArgumentNullException
cronExpressionis null.- ArgumentOutOfRangeException
formatis not a cron format.- FormatException
cronExpressionis not a valid cron expression informat.
- See Also
InTimeZone(TimeZoneInfo?)
The TimeZoneInfo in which to base the schedule.
public CronScheduleBuilder InTimeZone(TimeZoneInfo? timeZone)
Parameters
timeZoneTimeZoneInfothe time-zone for the schedule; null means the system's local time zone.
Returns
- CronScheduleBuilder
the updated CronScheduleBuilder
- See Also
WithMisfireInstruction(CronTriggerMisfireInstruction)
Say what the trigger should do when it misses a firing.
public CronScheduleBuilder WithMisfireInstruction(CronTriggerMisfireInstruction instruction)
Parameters
instructionCronTriggerMisfireInstructionthe policy to apply; defaults to SmartPolicy.
Returns
- CronScheduleBuilder
the updated CronScheduleBuilder
- See Also