lib/whirled_peas.rb in whirled_peas-0.2.0 vs lib/whirled_peas.rb in whirled_peas-0.3.0

- old
+ new

@@ -5,46 +5,40 @@ require 'whirled_peas/version' module WhirledPeas class Error < StandardError; end - DEFAULT_HOST = 'localhost' - DEFAULT_PORT = 8765 DEFAULT_REFRESH_RATE = 30 LOGGER_ID = 'MAIN' - def self.start(driver, template_factory, log_level: Logger::INFO, refresh_rate: DEFAULT_REFRESH_RATE, host: DEFAULT_HOST, port: DEFAULT_PORT) + def self.start(driver, template_factory, log_level: Logger::INFO, refresh_rate: DEFAULT_REFRESH_RATE) logger = Logger.new(File.open('whirled_peas.log', 'a')) logger.level = log_level logger.formatter = proc do |severity, datetime, progname, msg| if msg.is_a?(Exception) msg = %Q(#{msg.class}: #{msg.to_s}\n #{msg.backtrace.join("\n ")}) end "[#{severity}] #{datetime.strftime('%Y-%m-%dT%H:%M:%S.%L')} (#{progname}) - #{msg}\n" end - consumer = Frame::Consumer.new(template_factory, refresh_rate, logger) - consumer_thread = Thread.new do + event_loop = Frame::EventLoop.new(template_factory, refresh_rate, logger) + event_loop_thread = Thread.new do Thread.current.report_on_exception = false - consumer.start(host: host, port: port) + event_loop.start end - Frame::Producer.start(logger: logger, host: host, port: port) do |producer| + Frame::Producer.produce(event_loop: event_loop, logger: logger) do |producer| begin driver.start(producer) - producer.stop - rescue Errno::EPIPE - logger.error(LOGGER_ID) { 'Producer cannot connect to consumer, exiting...' } rescue => e logger.warn(LOGGER_ID) { 'Driver exited with error, terminating producer...' } logger.error(LOGGER_ID) { e } - producer.terminate raise end end - consumer_thread.join + event_loop_thread.join end def self.template(&block) template = UI::Template.new yield template, template.settings