lib/riemann/babbler/plugin_loader.rb in riemann-babbler-2.0.0pre11 vs lib/riemann/babbler/plugin_loader.rb in riemann-babbler-2.0.0pre13
- old
+ new
@@ -1,5 +1,7 @@
+require_relative 'plugin'
+
module Riemann
module Babbler
class PluginLoader
include Riemann::Babbler::Logging
@@ -17,19 +19,19 @@
'mega_cli',
'memory',
'net',
'runit',
'tw_cli',
- 'errors_reporter'
+ 'errors_reporter',
+ 'responder'
].freeze
- attr_accessor :sender, :load_plugin_names_from_config, :delete_from_autostart
+ attr_accessor :load_plugin_names_from_config, :delete_from_autostart
- def initialize(riemann)
- @sender = riemann
+ def initialize
@load_plugin_names_from_config = Array.new
- @delete_from_autostart = Array.new
+ @delete_from_autostart = Array.new
end
def all_available_plugins
default_plugins_dir = File.expand_path('../plugins/', __FILE__)
plugins = []
@@ -89,39 +91,31 @@
log :debug, "Require plugins: #{Riemann::Babbler::Plugin.registered_plugins}"
require_parents
require_from_config
end
- def run!
+ def plugin_to_start
started_plugins = []
plugin_names_to_run = AUTO_START +
opts.plugins.to_hash.keys.map { |name| name.to_s }
require_all_plugins!
plugin_names_to_run = plugin_names_to_run +
- load_plugin_names_from_config.map {|name| name.to_s}
+ load_plugin_names_from_config.map { |name| name.to_s }
plugin_names_to_run = (plugin_names_to_run - delete_from_autostart).uniq
Riemann::Babbler::Plugin.registered_plugins.each do |klass|
if plugin_names_to_run.include? name_to_underscore(klass.to_s)
started_plugins << klass
end
end
- plugin_threads = started_plugins.map do |plugin|
- Thread.new {
- log :unknown, "Start plugin #{plugin}"
- plugin.new(sender).run!
- }
- end
- Signal.trap 'TERM' do
- plugin_threads.each(&:kill)
- end
- plugin_threads.each(&:join)
+ log :debug, "Return plugin to start: #{started_plugins}"
+ started_plugins
end
end
end
end