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

发布于 2024-11-08 04:51:48 字数 836 浏览 0 评论 0原文

我对 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

并通过不使用 resque-status 创建后台工作程序

WordAnalyzer.create(word)

,它可以完美运行(调用 enqueue 而不是创建工作程序)。 通过 resque-status,我得到了

参数数量错误(2 比 1) /.../resque_test/lib/word_analyzer.rb:6:在“执行”中 /.../.rvm/gems/ruby-1.9.2-p136/gems/resque-1.16.1/lib/resque/job.rb:127:in `执行'

我搜索了文档和代码,但是没有找到将参数传递给 resque-status 作业的正确方法。是否可以?

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栩栩如生 2024-11-15 04:51:48

你应该

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文