Commit 298def43 authored by Marcel Hoppe's avatar Marcel Hoppe

skip active bunny loading on other rails commands than server and console

parent 1aff818a
......@@ -11,8 +11,10 @@ module ActiveBunny
private
def reload_subscriber
ActiveBunny.channel(self.name)
ActiveBunny.create_queues(self.name, class_name, method_list(ActiveBunny::Subscriber))
if Rails.const_defined? 'Server'
ActiveBunny.channel(self.name)
ActiveBunny.create_queues(self.name, class_name, method_list(ActiveBunny::Subscriber))
end
end
def reload_publisher
......@@ -35,4 +37,4 @@ module ActiveBunny
@class_name
end
end
end
\ No newline at end of file
end
......@@ -6,42 +6,45 @@ module Rails
module ActiveBunny
class Railtie < Rails::Railtie
config.active_bunny = ::ActiveBunny
if Rails.const_defined? 'Console' or Rails.const_defined? 'Server'
initializer "activebunny.load-config" do
if File.exists?(File.join(Rails.root, 'config', 'rabbitmq.yml'))
config.active_bunny.load_config("#{Rails.root}/config/rabbitmq.yml")
end
end
config.active_bunny = ::ActiveBunny
initializer "activebunny.file_watcher" do |app|
if File.exists?(File.join(Rails.root, 'config', 'rabbitmq.yml'))
app.reloaders << ActiveSupport::FileUpdateChecker.new([], { "app/subscribers" => [".rb"], "app/publishers" => [".rb"] }) do
puts "Active Bunny reloading..."
initializer "activebunny.load-config" do
if File.exists?(File.join(Rails.root, 'config', 'rabbitmq.yml'))
config.active_bunny.load_config("#{Rails.root}/config/rabbitmq.yml")
end
end
end
initializer "activebunny.connect_to_rabbitmq" do |app|
if File.exists?(File.join(Rails.root, 'config', 'rabbitmq.yml'))
config.active_bunny.connection
initializer "activebunny.file_watcher" do |app|
if File.exists?(File.join(Rails.root, 'config', 'rabbitmq.yml'))
app.reloaders << ActiveSupport::FileUpdateChecker.new([], { "app/subscribers" => [".rb"], "app/publishers" => [".rb"] }) do
puts "Active Bunny reloading..."
end
end
end
end
ActiveSupport::Reloader.to_prepare do
Railtie.load_stuff
::ActiveBunny::Publisher.descendants.each do |child|
child.send(:reload)
initializer "activebunny.connect_to_rabbitmq" do |app|
if File.exists?(File.join(Rails.root, 'config', 'rabbitmq.yml'))
config.active_bunny.connection
end
end
::ActiveBunny::Subscriber.descendants.each do |child|
child.send(:reload)
ActiveSupport::Reloader.to_prepare do
Railtie.load_stuff
::ActiveBunny::Publisher.descendants.each do |child|
child.send(:reload)
end
::ActiveBunny::Subscriber.descendants.each do |child|
child.send(:reload)
end
end
end
def self.load_stuff
if File.exists?(File.join(Rails.root, 'config', 'rabbitmq.yml'))
Dir.glob(File.join(Rails.root, 'app', 'publishers', '**', '*.rb'), &method(:require_dependency))
Dir.glob(File.join(Rails.root, 'app', 'subscribers', '**', '*.rb'), &method(:require_dependency))
def self.load_stuff
if File.exists?(File.join(Rails.root, 'config', 'rabbitmq.yml'))
Dir.glob(File.join(Rails.root, 'app', 'publishers', '**', '*.rb'), &method(:require_dependency))
Dir.glob(File.join(Rails.root, 'app', 'subscribers', '**', '*.rb'), &method(:require_dependency))
end
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment