【问题标题】:Resque workers fail immediately: undefined method `write' for nil:NilClassResque 工作人员立即失败:nil:NilClass 的未定义方法“写入”
【发布时间】:2013-01-25 02:14:56
【问题描述】:

我在我的 Rails 应用程序中使用 Resque(和 resque-scheduler)来运行重复性作业。直到今天,这对我来说都很好。我做了一些我认为不相关的代码更改,但现在每个工作人员在执行方法之前都失败了(使用调试语句检查)。当我在 Rails 控制台中运行相同的工作方法时,它可以正常工作。它仅通过开发本地主机(Postgres DB)上的 resque 失败。

resque 控制台中显示的失败工作人员的错误是:

Exception
    NoMethodError
Error
    undefined method `write' for nil:NilClass

错误没有额外的堆栈跟踪。知道为什么会失败吗?

附加信息:

lib/tasks/resque.rake

# Resque tasks
require 'resque/tasks'
require 'resque_scheduler/tasks'

namespace :resque do
  task :setup do
    require 'resque'
    require 'resque_scheduler'
    require 'resque/scheduler'

    # you probably already have this somewhere
    Resque.redis = 'localhost:6379'

    # If you want to be able to dynamically change the schedule,
    # uncomment this line.  A dynamic schedule can be updated via the
    # Resque::Scheduler.set_schedule (and remove_schedule) methods.
    # When dynamic is set to true, the scheduler process looks for
    # schedule changes and applies them on the fly.
    # Note: This feature is only available in >=2.0.0.
    #Resque::Scheduler.dynamic = true

    # The schedule doesn't need to be stored in a YAML, it just needs to
    # be a hash.  YAML is usually the easiest.
    Resque.schedule = YAML.load_file("#{Rails.root}/config/resque_schedule.yml")

    # If your schedule already has +queue+ set for each job, you don't
    # need to require your jobs.  This can be an advantage since it's
    # less code that resque-scheduler needs to know about. But in a small
    # project, it's usually easier to just include you job classes here.
    # So, something like this:
    # require 'jobs'
  end
end

task "resque:setup" => :environment do
  #ENV['QUEUE'] = '*'

  Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end

config/resque.yml

development: localhost:6379
test: localhost:6379:1
staging: redis1.se.github.com:6379
fi: localhost:6379
production: redis1.ae.github.com:6379

初始化程序/resque.rb

rails_root = Rails.root || File.dirname(__FILE__) + '/../..'
rails_env = Rails.env || 'development'

resque_config = YAML.load_file(rails_root.to_s + '/config/resque.yml')
Resque.redis = resque_config[rails_env]

# This will make the tabs show up.
require 'resque_scheduler'
require 'resque_scheduler/server'

config/resque_schedule.yml

populate_game_data:
  # you can use rufus-scheduler "every" syntax in place of cron if you prefer
  every: 1m
  # By default the job name (hash key) will be taken as worker class name.
  # If you want to have a different job name and class name, provide the 'class' option
  class: PopulateDataWorker
  queue: high
  args:
  description: "This job populates the game and data"

需要注意的是,上述文件在工作和非工作状态之间没有变化。

【问题讨论】:

  • 您能提供更多背景信息吗?工人阶级的代码将是一个好的开始。
  • 您可以回滚更改或查看更改吗?由于没有有关更改的信息,很难猜测出了什么问题。
  • @sgrif 我不认为工人类代码是相关的,因为它甚至在执行之前就失败了。为了确认,我注释掉了worker方法中的所有代码,我得到了相同的结果。
  • @d33pika 我所做的更高级别的更改之一是开始使用序列化属性(存储在数据库的“文本”字段中)。
  • @Kohanz 你能给我们一些你在哪里排队的代码吗?也许来自你的初始化程序?这个错误对我来说意味着 $stdin 在某处被设置为 nil ,或者期望文件没有得到它——但如果没有看到一些代码,我就忍不住了。

标签: ruby-on-rails resque


【解决方案1】:

我们今天早上遇到了同样的问题,我们将其归结为 New Relic 的宝石更新。 newrelic_rpm 的 3.5.6.46 版本在 ruby​​gems 上被删除,但不知何故它是通过包更新安装的。

他们仍处于 3.5.6 的测试版轨道上,并且在使用 Resque 时遇到了一些问题。见https://github.com/newrelic/rpm/commit/e81889c2bce97574ec682dafee12015e13ccb2e1

解决方法是在我们的 Gemfile 中为 newrelic_rpm 添加 '~> 3.5.5.38'

【讨论】:

  • 做到了。谢谢!出于好奇,是什么让您想到了新的遗物 RPM?
猜你喜欢
  • 2011-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
  • 2019-12-29
  • 1970-01-01
相关资源
最近更新 更多