问题
I think the title says it all.
I would like to run a job that e.g. Starts at Jun 19 2014 (say at 7 AM), ends at December 25 2015 (say at 11 PM) and runs every 9 days in between these two dates. I can set it up to work without an end date. But I don't know how to include all of it in one expression.
Update:
Does adding an EndAt()
to my TriggerBuilder
work?
mytrigger = (ICronTrigger)TriggerBuilder.Create()
.WithIdentity(triggerName, triggerGroup)
.WithCronSchedule(cron)
.EndAt(xxxx)
.Build();
回答1:
You're in the right direction, schedules that need a lot of research to be generated with a cron expression can be easily generated via the API. For example, the trigger you want is the following:
var startDate = new DateTime(2014, 06, 19, 7, 0, 0);
var endDate = new DateTime(2015, 12, 25, 23, 0, 0);
var cronExpression = "0 0 12 1/9 * ? *"; //every nine days
ITrigger trig = TriggerBuilder.Create()
.StartAt(startDate)
.WithCronSchedule(cronExpression)
.WithDescription("description")
.WithIdentity(triggerKey)
.WithPriority(1)
.EndAt(endDate)
.Build();
If you want to see the cron expression generated:
ICronTrigger trigger = (ICronTrigger)trig;
string cronExpression = trigger.CronExpressionString;
来源:https://stackoverflow.com/questions/26591225/run-a-job-every-x-days-but-only-between-two-specific-dates-and-times