ruby-on-rails - Resque工作线程立即失败: undefined method `write' for nil:NilClass

标签 ruby-on-rails resque

我在 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

配置/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'

配置/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"

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

最佳答案

今天早上我们遇到了同样的问题,我们将其归咎于 New Relic 的 gem 更新。 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”

关于ruby-on-rails - Resque工作线程立即失败: undefined method `write' for nil:NilClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14514281/

相关文章:

ruby-on-rails - 如何查明一组 Resque 作业是否已完成?

redis - 管理 Resque 和 Redis 的多个实例

ruby-on-rails - 访问 activeadmin 时未定义的方法 `authenticate_admin_user!'

ruby-on-rails - 从 If JSON 中拯救

ruby-on-rails - 有没有办法排除 Rollbar for Ruby 中报告的警告?

java - 如何在 Jesque 中使用 ConfigBuilder 配置 Heroku redis 连接?

ruby-on-rails - 我可以即时创建 resque 队列吗

ruby-on-rails - ActiveSupport::JSON.decode 无法正确处理文字换行符

ruby-on-rails - 在 Heroku、PostgreSQL 和 Rails 5 上运行迁移时出错

ruby-on-rails - 同一个 Rails 应用程序的两个 Redis 服务器