2013-01-25 43 views
2

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

應該注意上述文件在工作和非工作狀態之間沒有改變。

+0

你能不能給多一點背景?你的工人班的代碼將是一個好的開始。 – sgrif

+0

您可以回滾更改或查看它們嗎?沒有關於這些更改的信息,很難猜出出了什麼問題。 – d33pika

+0

@sgrif我不認爲工人類代碼是相關的,因爲它甚至在它被執行之前就失敗了。爲了確認,我註釋了worker方法中的所有代碼,並得到了相同的結果。 – Kohanz

回答

4

今天早上我們遇到了同樣的問題,我們把它固定在New Relic的寶石更新上。 newrelic_rpm的版本3.5.6.46在rubygems上被抽出,但它是通過軟件包更新以某種方式安裝的。

它們仍處於3.5.6的測試階段,並且遇到了Resque的一些問題。見https://github.com/newrelic/rpm/commit/e81889c2bce97574ec682dafee12015e13ccb2e1

此修復程序是在我們的Gemfile添加「〜> 3.5.5.38」爲newrelic_rpm

+0

這樣做。謝謝!出於好奇,什麼指向新的遺物RPM? – Kohanz

相關問題