Resque工作者出现“NoMethodError: undefined method `perform`”错误。

6
我不知道我在这里做了什么,但我尝试让Rails中的一个控制器将作业排队到Resque上,然后一个工作进程连接并执行繁重的工作(例如比较、数据库条目)。然而,由于没有设置Resque的明确说明,这些任务甚至没有运行。
以下是复制和粘贴的内容: 也可以在Gist格式中使用! 这是来自Hoptoad的异常行:
NoMethodError: undefined method 'perform' for Violateq:Module

这是“worker”文件的内容:
module Violateq
  @queue = :violateq

  def perform(nick, rulenumber)
    # Working for the weekend!!!
    puts "I got a nick of #{nick} and they broke #{rulenumber}"
    @violation = Violation.new(nick, rulenumber)
    puts "If you got this far, your OK"
    log_in(:worker_log, {:action => "Violate d=perfom", :nick => nick, :rulenumber => rulenumber, :status => "success"})
    #rescue => ex
    # notify_hoptoad(ex)
    # log_in(:worker_log, {:action => "Violate d=perfom", :nick => nick, :rulenumber => rulenumber, :status => "failure"})
  end

end

这是“web_controller”文件的内容:
class IncomingController < ApplicationController
  require 'mail'
  skip_before_filter :verify_authenticity_token

  def create
    message = Mail.new(params[:message])
    # Push the message into the queue
    Resque.enqueue(Violateq, message.from.to_s, message.subject.to_s)
    log_in(:endpoint_log, {:action => "IncomingController d=create", :subject => message.subject, :message => message.body.decoded})
    render :text => 'success', :status => 200 # a status of 404 would reject the mail
  rescue => ex
      notify_hoptoad(ex)
      render :text => 'failure', :status => 500
  end
end

非常感谢您的时间,如果您需要更多信息,请随时与我联系。
卢克·卡彭特
1个回答

17

已修复。
def perform更改为def self.perform
然后它就起作用了。

谢谢,
卢克·卡彭特


谢谢,老兄。这个救了我大忙。我正在阅读这篇文章http://blog.redistogo.com/2010/07/26/resque-with-redis-to-go/,他们的代码有误(也许只是旧版本?),但用这个就可以了。 - rafamvc
这也帮了我大忙,而且我实际上正在阅读上面那个人链接的同一篇文章。 - Aaron Ash

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接