我对resque很新,但它看起来非常适合我的需求。
实际上,我正在尝试设置一个简单的测试应用程序,如:
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
通过
创建后台工作者WordAnalyzer.create(word)
没有resque-status,它完美地工作(调用enqueue而不是创建worker)。 有了resque-status,我得到了一个
错误的参数数量(2对1) /.../resque_test/lib/word_analyzer.rb:6:在`perform' /.../.rvm/gems/ruby-1.9.2-p136/gems/resque-1.16.1/lib/resque/job.rb:127:in`exese'
我搜索了文档和代码,但没有找到将参数传递给resque-status工作的正确方法。有可能吗?
提前致谢。
答案 0 :(得分:8)
你应该做
WordAnalyzer.create(:word => word)
并通过
访问执行方法中的单词 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