救援工人生产失败

发布于 2024-11-17 00:56:42 字数 846 浏览 1 评论 0原文

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

  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>

I have a model which contains the following:

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

This dispatches the app/workers/fetch_austlii_job.rb file:

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

In development (OS X, Ruby 1.9.2, Rails3, Postgres, Redis-server, Foreman) it works fine. The job retrieves information from the internet just like it should. However, in production (Ubuntu, Ruby 1.9.2, Passenger) it fails with:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愛上了 2024-11-24 00:56:42

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

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

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'

Make sure you're running the workers in the correct environment (production vs development) on the server.

If you haven't already tried, you may want to create a config/setup_load_paths.rb to load the RVM environment (source: 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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文