每X天运行一次作业,但只在两个特定的日期和时间之间运行 [英] Run a job every X days but only between two specific dates and times
问题描述
我想运行一个工作,例如:从2014年6月19日(例如上午7点)开始,到2015年12月25日(例如下午11点)结束,并且在这两个日期之间每9天运行一次。我可以设置它工作没有结束日期。但是我不知道如何将它包含在一个表达式中。
更新:
添加 EndAt()
到我的 TriggerBuilder
工作?
code> mytrigger =(ICronTrigger)TriggerBuilder.Create()
.WithIdentity(triggerName,triggerGroup)
.WithCronSchedule(cron)
.EndAt(xxxx)
。 ();
您的方向正确,使用cron表达式生成的大量研究可以通过API轻松生成。例如,您想要的触发器如下:
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 *?*; //每9天
ITrigger trig = TriggerBuilder.Create()
.StartAt(startDate)
.WithCronSchedule(cronExpression)
.WithDescription
.WithIdentity(triggerKey)
.WithPriority(1)
.EndAt(endDate)
.Build();
如果您想查看生成的cron表达式:
ICronTrigger trigger =(ICronTrigger)trig;
string cronExpression = trigger.CronExpressionString;
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();
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;
这篇关于每X天运行一次作业,但只在两个特定的日期和时间之间运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!