我无法从 resque worker 中包含的模块调用方法。在下面的示例中,当我尝试调用say
工作程序(位于 TestLib 模块中)内部的方法时,我不断收到未定义的方法错误。为了说明问题,我已将代码简化为最基本的内容:
控制器 (/app/controllers/test_controller.rb)
class TestController < ApplicationController
def testque
Resque.enqueue( TestWorker, "HI" )
end
end
库 (/lib/test_lib.rb)
module TestLib
def say( word )
puts word
end
end
工人 (/workers/test_worker.rb)
require 'test_lib'
class TestWorker
include TestLib
@queue = :test_queue
def self.perform( word )
say( word ) #returns: undefined method 'say' for TestWorker:Class
TestLib::say( word ) #returns: undefined method 'say' for TestLib::Module
end
end
耙子文件 ( resque.rake )
require "resque/tasks"
task "resque:setup" => :environment
我正在使用以下命令运行 resque:rake environment resque:work QUEUE='*'
宝石:rails (3.0.4) redis (2.2.2) redis-namespace (1.0.3) resque (1.19.0)
服务器:nginx/1.0.6
有人对那里发生的事情有任何想法吗?