One time only Cron Expression

Marc L June 15, 2016

Is there a Cron Expression for a filter subscription that will run once 12 hours after the issue is created? Any help is appreciated.

2 answers

0 votes
crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 15, 2016

Well, yes and no.  You can certainly create a cron expression that will mean 12 hours from now and never again, but doing so reliably is not simple and there are a lot of edge cases.

Let's say that it is currently 2:00 P.M. on Wed 15 Jun 2016 in my time zone.  This cron expression would do it:

0 0 2 16 6 ? 2016

Because 2 A.M. on the morning of Thu 16 Jun 2016 is the only time that cron expression will ever match.  But things aren't as simple as that makes it sound, because:

  • You have to deal with the time rollover from hours to day-of-month (taking leap year into account) to month to year.  Such time calculations are fraught with peril and java.util.Calendar is one of the worst APIs in existence.  The joda-time library or the JDK 8 java.time package can help you do this correctly.
  • Trying to cheat is a very bad idea.  If I thought I could get away with just moving the hours by 12, I would have gotten a nasty shock at 2 P.M. on 4 Oct 2014, because I would have tried to schedule it for 2 A.M. on the 5th, but... that's a daylight savings gap.  The time jumps from 1:59 A.M. to 3:00 A.M. on that day, so 2 A.M. doesn't exist at all.
  • Due to how the calculations work, it might be impossible if there is a daylight saving overlap instead.  When there are two equally valid times for a cron expression to match (say there are two occurrences of 2 A.M. on that day) the later time is the only one that is honoured.  If the first 2 A.M. was the one you wanted, too bad – your job will run 13 hours later instead of 12.
  • Unlike run-once schedules the are explicitly created as one through the scheduler API, these kinds of schedules would not clean themselves up automatically – you would have to remove them yourself.

This kind of stuff is possible to do from plugin land.  You could create your own JobRunner that schedules using the proper atlassian-scheduler run-once mode with an interval delay, instead, and react to that by running the appropriate filter subscription directly.  The job would clean itself up, so all you would need to do is delete the filter subscription if it is no longer needed.

0 votes
GabrielleJ
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2016

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events