我正在努力让工作延迟工作作为佣金任务,但对于我的生活,我无法弄清楚我做错了什么。鉴于以下设置:
#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
即使我在运行测试用例或直接测试用例时没有收到此错误。有什么想法吗?
答案 0 :(得分:3)
DelayedJob在handle_asynchronously
中定义Delayed::MessageSending::ClassMethods
。 DelayedJob会自动将该模块修补为Module
中的lib/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