【问题标题】:Resque worker gives out "NoMethodError: undefined method `perform`"Resque 工作人员发出“NoMethodError:未定义的方法`perform`”
【发布时间】:2011-04-30 10:00:15
【问题描述】:

我不知道我在这里做了什么,但我试图让 Rails 中的一个控制器将作业排队到 Resque,然后工作人员连接到 Resque 并执行繁重的工作(IE 比较、数据库条目)。 但是,这些任务甚至都没有运行,因为没有明确的说明来设置 Resque。

复制粘贴以下内容:
Also available in Gist format!

这是来自 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

非常感谢您抽出宝贵时间,如果您想了解更多信息,请随时与我联系,
卢克·卡彭特

【问题讨论】:

    标签: ruby ruby-on-rails-3 resque


    【解决方案1】:

    已修复。
    def perform 更改为 def self.perform
    然后就成功了

    谢谢,
    卢克·卡彭特

    【讨论】:

    • 谢谢老兄。这节省了我很多时间。我正在阅读此 blog.redistogo.com/2010/07/26/resque-with-redis-to-go 并且他们的代码是错误的(可能只是来自旧版本?)并且它可以工作。
    • 这也救了我,我实际上正在阅读上面那个人链接到的同一篇文章。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 2012-04-24
    相关资源
    最近更新 更多