Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Create a TRICKY Scheduled trigger using CRON expressions

Nahuel Logghe February 21, 2024

Hello everyone,

I'm looking to set up a scheduled task that runs every 5 minutes, but it should only activate outside of standard working hours. Our working hours are from 8 AM to 5 PM CET, Monday to Friday. From what I understand, achieving this with just one CRON expression isn't feasible, right?

Could anyone suggest an alternative approach for implementing this? How can I accomplish this task?

2 answers

0 votes
Nahuel Logghe February 23, 2024

Is it possible to use the trigger every x minutes, regardless of time and day, and use IF conditions to add the other variables?

are there any smart values I can use for this?

Kenneth Henseler February 23, 2024

That was going to be next suggestion, but would need to test this to know for sure. Thought you might be able to use a date comparison, but Atlassian's Business Day is slightly different than yours: Examples of using smart values with dates | Cloud automation Cloud | Atlassian Support.

Nahuel Logghe February 26, 2024

I created a "solution", I'm just unsure if it is working as I intended. Give me your opinion, please.

I'm using a branch rule to compare each variable, using "now.format" for the day of the week and "now.hour" to check the time. Like this:

Branch:

For: Current Issue

Check if : {{now.format("EEEE")}} equal "Saturday"

Then: Send email

Branch:

For: Current Issue

Check if : {{now.format("EEEE")}} equal "Sunday"

Then: Send email

Branch:

For: Current Issue

Check if : {{now.hour}} greater than 17

Then: Send email

 

So basically if it's not Saturday it will check if it's Sunday, and if it's not Sunday either it will check the time, etc. Did I do this properly?

 

Nahuel Logghe February 27, 2024

I made a mistake, I'm actually using {{now.dayOfWeekName}} instead of {{now.format("EEEE")}}.

I'm unsure if it works though

Like Kenneth Henseler likes this
Kenneth Henseler February 27, 2024

Your logic appears to be correct, based on your requirements. Test it and see! The Send Email action might create a bit of noise while you’re testing, but if that’s acceptable, go for it. You might consider setting the action to just comment on an existing issue too. Either way, put it to test and make sure it works as intended. Good work!

Like Nahuel Logghe likes this
Nahuel Logghe February 28, 2024

Thanks for the help and support. I'll post again to show if it worked

0 votes
Kenneth Henseler February 21, 2024

To run a cron job every 5 minutes, excluding business hours, you can use the following expression:

*/5 17-7 * * 1-5

Explanation:

*/5: This means every 5 minutes.
17-7: Specifies the hours from 5 PM to 7:59 AM (outside business hours).
*: Represents all days of the month.
*: Represents all months.
1-5: Refers to Monday through Friday (business days).
So, the cron job will execute every 5 minutes between 5 PM and 8 AM on weekdays (Monday to Friday).

Nahuel Logghe February 22, 2024

Hi Kenneth,

thanks for the answer. I don't think I have explained myself correctly.

What I need is for it to run outside of business hours Monday through Friday. But on Saturdays and Sundays it has to run all day, since weekend is also out of business hours.

Also, cron does not allow expressions like 17-7 that cross from one day to the next. The allowed values are 0-23, hence my dilemma (or at least one of them)

So far I come out with 3 expressions, but I cannot run them in the same rule, can I? That would be the best because I don't want to have 3 rules for the same alert:

*/5 0-8 * * 1-5 -> every 5th minute, every hour from 0 through 8hs on every day-of-week from Monday through Friday.

*/5 17-23 * * 1-5 -> This one schedules the task to run every 5 minutes from 17  to 23hs on Monday to Friday.

*/5 * * * 6,0 -> Weekends all day. 

Can I run these 3 cron expressions on one rule? Or somewhat combine them?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events