Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 是否可以将参数传递给(resque status)resque::JobWithStatus?_Ruby_Backgroundworker_Resque - Fatal编程技术网

Ruby 是否可以将参数传递给(resque status)resque::JobWithStatus?

Ruby 是否可以将参数传递给(resque status)resque::JobWithStatus?,ruby,backgroundworker,resque,Ruby,Backgroundworker,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}"

我是个新手,但它看起来真的很适合我的需要

实际上,我正在尝试设置一个简单的测试应用程序,如:

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
如果没有resque状态,它可以完美地工作(通过调用enqueue而不是创建worker)。 有了resque状态,我得到了一个

参数数量错误(2对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'

我搜索了docu和代码,但没有找到将参数传递给resque状态作业的正确方法。可能吗

提前谢谢。

你应该这样做

WordAnalyzer.create(:word => word)
并在perform方法中通过

  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

哦,我的。。。我误解了文档中的选项散列。它的工作原理类似于WordAnalyzer。创建(:word=>word),然后在实例(而不是类)方法中访问选项['word'],因为它是一个符号,“word”是一个字符串。如果您想使用
选项[:word]
,可能您必须执行
WordAnalyzer.create(:word=>word.to_sym)
。我还没有试过呢!
  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