Interval CRON expression with specific start and stop times

Dani Sill July 1, 2021

I currently have the CRON expression for an automation that runs every two hours as follows:

0 0 0/2 ? * MON-FRI

However, due to the time zone distribution of my team, we'd like to tighten the period of this automation to exclude time around the weekend. I understand that the expression as written currently will start at 12:00am (midnight) UTC on Monday and last run will be around 10:00pm UTC on Friday. I'd like to modify it so that it insteads starts at 8am on Monday and then runs continuously every two hours until 6pm on Friday. Is this possible to do in a single expression?

 

In the worst case I think I'd split it into three expressions: one for Monday to start late, one for Tuesday through Thursday continuously, and one for Friday to end early, though this is less than ideal since it would result in extra work any time we would need to make changes in the future.

1 answer

0 votes
Angélica Luz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 5, 2021

Hello @Dani Sill,

Welcome to the Atlassian Community!

Thank you for sharing the details.

Checking the documentation and also some websites that help with building CRON expressions, I believe that the one that fits your requirements would be:

0 0 8,10,12,14,16,18 ? * MON-FRI *

I used this one and here are the results of the next execution dates:

Screen Shot 2021-07-05 at 12.21.19.png

Please, take your time to test and let us know how it goes.

Kind regards,
Angélica

Dani Sill July 6, 2021

Hi Angélica,

Your example would miss times that I would want the job to run, for example, I would want these times that are missing from your screenshot:

Mon Jul 05 20:00:00 UTC 2021

Mon Jul 05 22:00:00 UTC 2021

Tue Jul 06 00:00:00 UTC 2021

Tue Jul 06 02:00:00 UTC 2021

Tue Jul 06 04:00:00 UTC 2021

Tue Jul 06 06:00:00 UTC 2021

Angélica Luz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 7, 2021

Hi Dani,

I’m sorry for the misunderstanding, I thought you needed the automation to run from 8 am to 6 pm every day.

We checked here and found out that it’s not possible to do what you need with only one rule, it will be necessary to use three.

The first one will work for Mondays, it will start at 08:00 and end at 22:00: 

0 0 8/2 ? * MON *

The second one will start at midnight (Tuesday) and it will end at 22:00 on Thursday:

0 0 0/2 ? * TUE,WED,THU *

The last one will start at midnight (Friday) and end at 18:00 on Friday as well:

0 0 0-18/2 ? * FRI *

Hope this helps!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events