resque 未正确加载 Rails 环境
我正在转换一个工作应用程序以通过 resque 处理传入请求。作业已正确提交至 reque。当工作人员获取任务并开始执行时,问题就开始了。
在我的应用程序中,当我尝试引用其中一个字段时,我的模型之一出现错误。类关键字 < ActiveRecord::基础 调用是“Keyword.first.rule”,这将返回“尝试调用私有方法”。
当我在工作程序调用我的应用程序之前在工作程序中添加以下代码片段时,问题就消失了。
def self.perform(phone_number,message,short_code)
k = Keyword.first
k.rule
Parser.new.parse_request(phone_number,message,short_code)
end
在我解决了这个问题之后,其他随机错误开始出现在之前正常工作的代码上。 ex casecmp 不是有效的方法。 我确信这不是我的代码的问题,因为当我从 Rails 控制台调用相同的方法时,它工作得很好。
这是我的设置 - ruby 1.8.7 (2010-01-10 补丁级别 249) [x86_64-linux] - 宝石 1.3.5 - 导轨 2.3.8 - 请求 1.17.1 - Ubuntu 10.04.3 LTS
Worker
class ProcessMo
@queue = :incoming_messages_queue
def self.perform(phone_number,message,short_code)
Parser.new.parse_request(phone_number,message,short_code)
end
end
resque.rake
require "resque/tasks"
task "resque:setup" => :environment
I was converting a working application to process incoming requests via resque. The jobs get submitted to resque properly. The problem starts when the worker grabs a task and starts executing.
Inside my application I got an error with one of my models when i tried to refer to one of the fields. class Keyword < ActiveRecord::Base
The call was 'Keyword.first.rule' This would return "Attempt to call private method".
The problem went away when i added the following snippet in the worker before it called my application
def self.perform(phone_number,message,short_code)
k = Keyword.first
k.rule
Parser.new.parse_request(phone_number,message,short_code)
end
After I got passed this problem other random errors started cropping up on the code that used to work properly before. ex casecmp is not valid method.
I am convinced this is not an issue with my code because when i call the same methods from the rails console it works perfectly fine.
This is my setup
- ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
- gem 1.3.5
- rails 2.3.8
- resque 1.17.1
- Ubuntu 10.04.3 LTS
Worker
class ProcessMo
@queue = :incoming_messages_queue
def self.perform(phone_number,message,short_code)
Parser.new.parse_request(phone_number,message,short_code)
end
end
resque.rake
require "resque/tasks"
task "resque:setup" => :environment
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从错误消息来看,该部分代码之前似乎有以下内容:
From the error message, it sounds like the following is before that section of code: