2010-01-29 165 views
2

我想要延遲工作來作爲耙工作,但對於我的生活,我無法弄清楚我做錯了什麼。鑑於以下設置:延遲作業耙任務失敗

#config/environment.rb 
Rails::Initializer.run do |config| 
    config.gem 'delayed_job' 
end 

#Rakefile 
begin 
    require 'delayed/tasks' 
rescue LoadError 
    STDERR.puts "Run `rake gems:install` to install delayed_job" 
end 

#Observer 
class SomeObserver < ActiveRecord::Observer 
    def foo(bar) 
    end 
    handle_asynchronously :foo 
end 

每當我運行rake作業:清楚,我收到以下錯誤:

undefined method `handle_asynchronously' for SomeObserver:Class 

即使當我跑步時的測試情況下,我沒有得到這個錯誤或它直接。有任何想法嗎?

回答

3

DelayedJob在Delayed::MessageSending::ClassMethods中定義了handle_asynchronously。 DelayedJob會自動將該模塊修補到Modulelib/delayed_job.rb中。你可能有更好的運氣,要求在你的Rake任務中:

#Rakefile 
begin 
    require 'delayed_job' 
    require 'delayed/tasks' 
rescue LoadError 
    STDERR.puts "Run `rake gems:install` to install delayed_job" 
end