开发者

Delayed Job Rake Task Failing

I'm trying to get delayed job to work as a rake task, but for the life of me I can't figure out what I'm doing wrong. Given the following setup:

#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

Whenever I run rake jobs:clear I get the following error:

undefined method `handle_asynchronously' for SomeObserver:Class

Even though I don't get this error when I'm running the test cases or it directly. Any开发者_如何学Go ideas?


DelayedJob defines handle_asynchronously in Delayed::MessageSending::ClassMethods. DelayedJob automatically monkey-patches that module into Module in its lib/delayed_job.rb. You'll likely have better luck requiring that in your Rake task:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜