0

I am using whenever gem to schedule jobs but I am not able to figure out how to schedule a job for the end of each month. Below is the which I want to run at the end of each month.

schedule.rb

every 1.month, at: 'end of the month at 5am' do
  rake 'update_user', environment: ENV['RAILS_ENV']
end

Please help me fix this

user12763413
  • 1,177
  • 3
  • 18
  • 53

1 Answers1

0

Last day of the month is tricky in a cron job but you could use raw cron syntax to specify start of each month to run a job as follows:

#runs on at 12:00AM on the first of each month
every '0 0 1 * *' do
    command "echo 'you can use raw cron syntax too'"
end

The syntax is minute, hour, day of month, month, day of week.

If running the job at the start of the month isn't an option, you could schedule the job run daily on the 28th-31st day each month and add logic in your take to only execute the job on the last day of each month as described in this answer

cadair
  • 96
  • 6