One time only Cron Expression

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

This widget could not be displayed.
Chris Fuller Atlassian Team Jun 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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

126 views 1 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you