Permalink
Browse files

Move backend setup into config.after_initialize

  • Loading branch information...
1 parent 59c1544 commit 0a4ffb436a1b878b49bec4b6077fd87e3339d4e2 @bkeepers bkeepers committed Mar 26, 2010
Showing with 14 additions and 10 deletions.
  1. +0 −1 init.rb
  2. +0 −9 lib/delayed_job.rb
  3. +12 −0 rails/init.rb
  4. +2 −0 spec/spec_helper.rb
View
1 init.rb
@@ -1 +0,0 @@
-require File.dirname(__FILE__) + '/lib/delayed_job'
View
9 lib/delayed_job.rb
@@ -8,15 +8,6 @@
Object.send(:include, Delayed::MessageSending)
Module.send(:include, Delayed::MessageSending::ClassMethods)
-if defined?(ActiveRecord)
- Delayed::Worker.backend = :active_record
-elsif defined?(MongoMapper)
- Delayed::Worker.backend = :mongo_mapper
-else
- $stderr.puts "Could not decide on a backend, defaulting to active_record"
- Delayed::Worker.backend = :active_record
-end
-
if defined?(Merb::Plugins)
Merb::Plugins.add_rakefiles File.dirname(__FILE__) / 'delayed' / 'tasks'
end
View
12 rails/init.rb
@@ -0,0 +1,12 @@
+require 'delayed_job'
+
+config.after_initialize do
+ Delayed::Worker.backend ||= if defined?(ActiveRecord)
+ :active_record
+ elsif defined?(MongoMapper)
+ :mongo_mapper
+ else
+ Delayed::Worker.logger.warn "Could not decide on a backend, defaulting to active_record"
+ :active_record
+ end
+end
View
2 spec/spec_helper.rb
@@ -27,6 +27,8 @@
DEFAULT_BACKEND = backends_available.first.to_sym
+Delayed::Worker.backend = DEFAULT_BACKEND
+
backends_available.each do |backend|
require "setup/#{backend}"
require "backend/#{backend}_job_spec"

0 comments on commit 0a4ffb4

Please sign in to comment.