Search code examples
ruby-on-railsrubycron

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.


Solution

  • 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