0

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();
disasterkid
  • 6,948
  • 25
  • 94
  • 179
  • Show us your current config – Martin Oct 27 '14 at 16:05
  • @Martin I was thinking to mention the start date and time in my cron and then when I add my trigger using `TriggerBuilder` I also add `endAt()`. Is that a good idea? – disasterkid Oct 27 '14 at 16:09
  • 1
    I'm not entirely sure what you mean with "mention start date and time in my cron", but setting endAt will ensure that the trigger will not fire after the endAt date – Martin Oct 27 '14 at 16:23
  • @Martin what I mean is that I can write my cron so that it starts on a specific date and time. But in order to add the end date I can create a my trigger using `TriggerBuilder` and add the ´endDate´ to its build as well. I will update my code above. – disasterkid Oct 27 '14 at 16:25

1 Answers1

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;
Nick Patsaris
  • 2,118
  • 1
  • 16
  • 18