我在我的Rails應用程序中使用Resque(和resque-scheduler)來運行重複作業。這對我來說工作得很好,直到今天。我做了一些代碼更改,我認爲這些更改是不相關的,但是現在每個worker都會在執行方法被輸入之前失敗(使用調試語句進行檢查)。當我在rails控制檯中運行它時,相同的工作方法正常工作。它只能通過在本地主機(Postgres DB)上重新啓動而失敗。Resque workers立即失敗:未定義的方法'寫'爲零:NilClass
在失敗工作者resque控制檯中顯示的錯誤是:
Exception
NoMethodError
Error
undefined method `write' for nil:NilClass
沒有爲錯誤沒有額外的堆棧跟蹤。任何想法爲什麼這是失敗?
附加信息:
的lib /任務/ 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"
應該注意上述文件在工作和非工作狀態之間沒有改變。
你能不能給多一點背景?你的工人班的代碼將是一個好的開始。 – sgrif
您可以回滾更改或查看它們嗎?沒有關於這些更改的信息,很難猜出出了什麼問題。 – d33pika
@sgrif我不認爲工人類代碼是相關的,因爲它甚至在它被執行之前就失敗了。爲了確認,我註釋了worker方法中的所有代碼,並得到了相同的結果。 – Kohanz