ECM
ECM
总版主
总版主
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:809回复:0

Run a job every X days but only between two specific dates and times

楼主#
更多 发布于:2016-05-16 10:53
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();
answer(解决方案):

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;

 

 

 

 

 

 

 

异常中心网是一家专门收集整理程序员编程过程中遇到的常见异常(exception)以及各种异常问答中心的网站。异常中心网旨在,减少程序员在编码遇到异常,处理各种异常时间和痛苦,让程序员能更愉快的、快速的定位异常并查找对应的异常解决方案。异常中心网诚心打造最完美的编程社区为程序员用户服务,努力成为最好的程序员乐园程序员社区程序异常中心程序bug中心异常问答中心

 

喜欢0 评分0
游客

返回顶部