Reputation: 21907
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.
Upvotes: 7
Views: 6338
Reputation: 72
you can easily use Whenever which exactly does what you asked and a lot more,it has a pretty good documentation.
you can use some syntax like this:
every 3.hours do
runner "MyModel.some_process"
rake "my:rake:task"
command "/usr/bin/my_great_command"
end
install it using:
$ gem install whenever
or add it to your GemFile:
gem 'whenever', :require => false
then run:
$ cd /apps/my-great-project
$ wheneverize .
hope this helps you!
Upvotes: 0
Reputation: 54782
Since you are already using Resque, I would recommend to use one of the many available Resque plugins: resque-scheduler. Plugs into the Resque UI very nicely as well. Simple setup as explained in the README. Also adds a lot of the missing DelayedJob stuff (delayed execution).
Why I switched from whenever
to resque-scheduler
:
resque-loner
you prevent double-execution should a job take longer than the span between two executions.Upvotes: 3
Reputation: 115541
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
Upvotes: 7