2

我在我的 Rails 应用程序中使用 Resque(和 resque-scheduler)来运行重复性作业。直到今天,这对我来说都很好。我做了一些我认为不相关的代码更改,但现在每个工作人员甚至在输入 perform 方法之前都失败了(使用调试语句检查)。当我在 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"

应该注意,上述文件在工作和非工作状态之间没有变化。

4

1 回答 1

4

今天早上我们遇到了同样的问题,我们将其归结为 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'

于 2013-01-25T10:42:16.117 回答