$:.unshift File.dirname(__FILE__) require 'smoke/client/signal_runner' module Smoke module Client def new(signals = []) @reporter = SignalRunner.new polling_signals, interupting_signals = returning([[], []]) do |poll, interupt| signals.map do |signal| if signal.instance_methods.include?("start") interupt << signal else poll << signal end end end interupting_signals.map do |signal| Thread.new(self) do |client| signal.new(client).start end end loop do polling_signals.map do |signal| Thread.new(@reporter) do |r| begin response = signal.run report(signal, response) rescue => e puts e.message + ":" + e.backtrace.join("\n") end end end # FIXME: This should be configurable. sleep 60 end end def report(signal, response) source = signal.is_a?(Class) ? signal.to_s : signal.class.to_s response.merge!(:source => source, :time => Time.now) @reporter.signals << response end extend self end end