【问题标题】:Resque workers failing in productionResque 工人在生产中失败
【发布时间】:2011-06-23 04:59:07
【问题描述】:

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

  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>

【问题讨论】:

    标签: ruby-on-rails-3 resque


    【解决方案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'
    

    【讨论】:

    • 生产服务器的环境变量 RAILS_ENV 设置为“生产”。我曾尝试将其切换为“开发”,但它以同样的方式出错。我怀疑Passenger 没有选择项目特定的RVM gem,尽管我不能确定。
    • 我已经编辑了我的答案,可能会解决乘客/RVM 问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    • 2023-04-09
    • 2010-12-16
    • 2014-09-07
    • 2012-06-08
    • 1970-01-01
    • 2016-09-03
    相关资源
    最近更新 更多