Sha256: 7491fdbca9c134e02953d02205a0efaee91d0dc80226c7f56b57470d95cbeeac
Contents?: true
Size: 1.25 KB
Versions: 22
Compression:
Stored size: 1.25 KB
Contents
module Riemann module Babbler class PluginManager include Riemann::Babbler::Logging include Riemann::Babbler::Errors def initialize(sender, array_of_klasses) @plugins = array_of_klasses @sender = sender @mapping = Hash.new end def run! @plugins.map do |plugin| unless plugin.new(@sender).send(:run_plugin) log :unknown, "Disable plugin: #{plugin}, because it not started by condition: run_plugin" next end @mapping[plugin] = run_thread(plugin) end loop do check_alive sleep 10 end end def run_thread(plugin) Thread.new { log :unknown, "Start plugin #{plugin}" plugin.new(@sender).run! Signal.trap('TERM') do shutdown end } end def check_alive log :debug, "Check alive of threads [#{@mapping.count}]" @mapping.each do |plugin, thread| next if thread.alive? log :error, "Plugin: #{plugin} is #{thread.inspect}, run it..." @mapping[plugin] = run_thread(plugin) end end def shutdown exit Errors::USER_CALL_SHUTDOWN end end end end
Version data entries
22 entries across 22 versions & 1 rubygems