【问题标题】:Problem using Resque, Rails 3 and Active-Recored使用 Resque、Rails 3 和 Active-Recored 的问题
【发布时间】:2011-04-26 22:15:44
【问题描述】:

我有这个要执行的响应由“Resque”运行的类,我在recipient.response = response.body 这一行有一个错误,即:

#Hash:0x00000003969da0 的未定义方法 response='

我认为这是因为 worker 和 ActiveRecord 不能一起工作。
PS我已经加载了我的环境和这个类放在lib目录中

使用:
红宝石 1.9.2
导轨 3
Resque 1.10.0

class Msg
  def self.perform(message,sender,host, path, recipient)
    message_logger ||= Logger.new("#{Rails.root}/log/message.log")
    response = Net::HTTP.get_response(host, path)
    begin
      recipient.response = response.body
      recipient.sent_at = Time.zone.now
      recipient.save
      # Logging
      log = "Message #{
      message.sent_at}\n\tRespone:\n\t\tBody: #{response.body}\n\t\tCode: #{response.code}\n"
      message_logger.info(log)
    rescue Exception => e
      message_logger.error(e.message + '/n' + e.backtrace.inspect)
    end
  end
end

【问题讨论】:

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


    【解决方案1】:

    Resque 使用 json 序列化。 JSON 序列化不允许您在方法完整的情况下反序列化对象。

    如果您有一个 Recipient 实例(名为“recipient”)并希望在方法中使用它来执行/持久响应响应,那么您应该将收件人的 id 排入队列并在调用 perform 时从持久层获取它.

    https://github.com/defunkt/resque(查看持久性部分)

    Resque 在这点上与 DelayedJob/Background Job 等不同。 (这就是我喜欢它的原因。同一个队列可以被多个 ruby​​ 实现共享,jruby,mri,...)

    【讨论】:

      【解决方案2】:

      这听起来根本不像 resque 和 activerecord 的问题。它说您传入的参数recipient 是一个哈希值。将作业排入队列的代码在哪里?您还可以查看您看到错误消息的工作人员的日志输出,以了解传递给作业的参数是什么。

      【讨论】:

        猜你喜欢
        • 2015-03-03
        • 1970-01-01
        • 1970-01-01
        • 2012-06-11
        • 1970-01-01
        • 1970-01-01
        • 2012-03-23
        • 1970-01-01
        • 2015-03-04
        相关资源
        最近更新 更多