What do you call a method every hour in Rails?

I am using Resque with Redis to handle a background job. I would like to call the Resque.enqueue (MyModel) method only once per hour to do the background job.

For example: Let's say I have a website with 10,000 users. I would call this method 24 times a day; not 10,000 * 24. Example method below:

Resque.enqueue(MyModel)

Thank you for your help. It should also be mentioned that I prefer to stick with Resque and not switch to the Delayed Job. Thank.

+5
source share
3 answers

You must use the cron job for this task.

I suggest you use the Whenever gem.

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

+5

Resque, Resque: resque-scheduler. Resque . , README. DelayedJob ( ).

whenever resque-scheduler:

  • cron.
  • "", Resque.
  • Resque.
  • Resque.
  • resque-loner , .
  • - Resque.
  • ( 60 , ), Resque worker-pool.
  • "".
  • : cron-like.
+3

Whenever, , , , .

:

every 3.hours do
    runner "MyModel.some_process"
    rake "my:rake:task"
    command "/usr/bin/my_great_command"
end

, :

$ gem install whenever

GemFile:

gem 'whenever', :require => false

:

$ cd /apps/my-great-project
$ wheneverize .

, !

0

All Articles