Search code examples
ruby-on-railsrubymethodstimeresque

How do you call a method every hour in Rails?


I'm using Resque with Redis to process a background job. I'd like to call the method, Resque.enqueue(MyModel) just one time every hour to do a background task.

For example: Say I have a site that has a 10,000 users. I would like to call this method only 24 times per day; not 10,000 * 24. The example method is below:

Resque.enqueue(MyModel)

Thank you for your help in advance. I should also mention I prefer to stick with Resque, and not move to Delayed Job. Thank you.


Solution

  • You should use a cron job for this kind of task.

    I suggest you use the Whenever gem.

    See railscast here: http://railscasts.com/episodes/164-cron-in-ruby