简体   繁体   中英

Cron expression for running rake task first Thursday of every month

I have written following ruby code in rails application :

every '20 8 1-7 * 4' do
  rake 'data_import:check_for_presence_of_file'
end

But above rake task is running ever day at 8:20 am GMT. Is there something wrong with expression ? I have searched internet for cron expression but I have seen conflicting information. Please help.

I'm not sure there is a way with cron. '20 8 1-7 * 4' means the first seven days of the month and on thursdays. Instead perhaps do it the first seven days of the month and in rails check if its thursday:

every '20 8 1-7 * *' do
  rake 'data_import:check_for_presence_of_file' if Date.today.thursday?
end

This is correct cron schedule for a Tuesday weekly:

20 8 * * 2

Here are more details: https://crontab.guru/#20_8_ _ _2

In your sample you are using 1-7 which means every day.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM