Search code examples
rubybackgroundworkerresque

Is it possible to pass arguments to a (resque-status) Resque::JobWithStatus?


I'm pretty new to resque, but it looks really good for my needs.

Actually, I'm trying to setup a simple test app like:

require 'resque'
require 'resque/job_with_status'
class WordAnalyzer < Resque::JobWithStatus
  @queue = "word_analysis"

  def self.perform(word)
    puts "About to do heavy duty analysis on #{word}"
    sleep 3 # fake analysis here
    # this would be something impressive
    puts "Finished with analysis on #{word}"
  end
end

And creating a background worker by

WordAnalyzer.create(word)

Without resque-status, it works perfectly (with calling enqueue instead of creating the worker). With resque-status, I get a

wrong number of arguments (2 for 1) /.../resque_test/lib/word_analyzer.rb:6:in `perform' /.../.rvm/gems/ruby-1.9.2-p136/gems/resque-1.16.1/lib/resque/job.rb:127:in `perform'

I've searched both docu and code, but didn't find the proper way of handing arguments to a resque-status job. Is it possible?

Thanks in advance.


Solution

  • You should do

    WordAnalyzer.create(:word => word)
    

    And access that word in perform method by

      def perform
        word = options['word']
        puts "About to do heavy duty analysis on #{word}"
        sleep 3 # fake analysis here
        # this would be something impressive
        puts "Finished with analysis on #{word}"
      end