0

I am using Resque to run a background process. This is how my background process works:

  1. Scans through all the rows in an ActiveRecord model
  2. Checks for a condition
  3. Updates the row if the condition is met

And this needs to go on infinitely.

This is how I am trying to use Resque for my purpose, here's my worker class:

class ThumbnailMaker
  @queue = :thumbnail_queue

  def self.perform()
    MyObj.check_thumbnails(root_url)
  end
end

I understand the perform() method keeps a task in a queue, which is run periodically. In my case, I need a task that scans the whole table, so it runs for a longer time. Is it a good solution to my requirements?

On another note, I need the root url for my Rails application, which is easily obtained with the root_url in Rails Controller. But I need it in a class I have created, can you suggest me how I can get it here?

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
rookieRailer
  • 2,313
  • 2
  • 28
  • 48

2 Answers2

1

Resque is for queueing tasks to be run in the background; each item in the queue runs once and then is removed. What you want is more like a scheduled task--for example, a custom Rake task or other script that runs from time to time; there are many scheduling gems available for this kind of thing (wenever is very popular) or just use cron. There is a great RailsCasts episode about this very topic.

Michelle Tilley
  • 157,729
  • 40
  • 374
  • 311
  • For your `root_url` question, see [this SO question](http://stackoverflow.com/questions/341143/can-rails-routing-helpers-i-e-mymodel-pathmodel-be-used-in-models) – Michelle Tilley Dec 13 '11 at 05:05
1

You might want to try putting your code in a rake task and running it periodically through a cron job. Resque/Redis seems a bit too much for your needs.

You may consider passing the root url in with as parameter if you are calling your class through your controller. Otherwise, you may want to set it as a ENV setting and configure each of your deployments accordingly.

Jaryl
  • 2,561
  • 1
  • 24
  • 33