Resque工人生产失败

时间:2011-06-23 04:59:07

标签: ruby-on-rails-3 resque

我有一个包含以下内容的模型:

  def fetch_austlii
    Resque.enqueue(FetchAustliiJob, self.id) # Queue the job for later.
  end

这将调度app / workers / fetch_austlii_job.rb文件:

class FetchAustliiJob

  @queue = :fetch_queue

  def self.perform(profile_id)
    @profile = Profile.find(profile_id)
    AustliiResource.fetch(@profile.name).each do |resource|
      @profile.austlii_resources.create!(resource.attributes) if @profile.austlii_resources.find_all_by_url(resource.url).empty?
    end
  end

end

在开发中(OS X,Ruby 1.9.2,Rails3,Postgres,Redis-server,Foreman)它可以正常工作。该工作就像它应该从互联网上检索信息。但是,在生产中(Ubuntu,Ruby 1.9.2,Passenger)它失败了:

Class
FetchAustliiJob
Arguments
2
Exception
NoMethodError
Error
undefined method `austlii_resources' for #<Profile:0x00000002fab6b0>

1 个答案:

答案 0 :(得分:1)

确保您在服务器上的正确环境(生产与开发)中运行工作程序。

如果您还没有尝试过,可能需要创建一个config/setup_load_paths.rb来加载RVM环境(来源:RVM Passenger docs):

if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
  begin
    rvm_path     = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
    rvm_lib_path = File.join(rvm_path, 'lib')
    $LOAD_PATH.unshift rvm_lib_path
    require 'rvm'
    RVM.use_from_path! File.dirname(File.dirname(__FILE__))
  rescue LoadError
    # RVM is unavailable at this point.
    raise "RVM ruby lib is currently unavailable."
  end
end

ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
require 'bundler/setup'