Reputation: 32120
I want to have a certain controller's action to do something at a certain time (for instace, send the user email at New Years day
I want it to be done regardless if the user enters the site or not.
Is there a gem for this for timers in rails?
Upvotes: 0
Views: 548
Reputation: 6834
You can take a look to whenever gem, which writes and deploy cron jobs, so you are able to execute the task that you want at the time you want, for example:
every 3.hours do
runner "MyModel.some_process"
rake "my:rake:task"
command "/usr/bin/my_great_command"
end
every 1.day, :at => '4:30 am' do
runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
end
every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
runner "SomeModel.ladeeda"
end
every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday
runner "Task.do_something_great"
end
every '0 0 27-31 * *' do
command "echo 'you can use raw cron syntax too'"
end
This example was taken from the whenever gem documentation, hope this helps.
Upvotes: 1