lib/broker/launcher.rb in broker-0.0.9 vs lib/broker/launcher.rb in broker-0.1.1

- old
+ new

@@ -1,8 +1,45 @@ require 'broker/utility' +require 'broker/queue' +require 'broker/import' +require 'broker/finder' module Broker + module Event + def register(arr) + arr || return + puts "Event has been registered with: #{arr.inspect}" + unless arr.empty? + begin + session = Broker::Import.new(:app => Broker.any_app) + rescue ArgumentError => e + @failed = true + puts "Cant login to QB, invalid app name" + puts e.message + end + @failed || transport(session) + end + + end + + def transport(session) + while !@queue.empty? + payload = @queue.next + results = payload.commit(session) + puts "#{results.inspect}" + @queue.success(payload) + # Need to handle failure and add payload to queues failed + # Need to handle success and move file out and alert queue + end + puts "Session Terminated: #{session.sign_out}" + puts "Processed: #{@queue.processed}" + puts "Pending: #{@queue.pending.inspect}" + puts "Failed: #{@queue.failed.inspect}" + end + + end + class Launcher def initialize @poller = Broker::Poller.new @finished = false @@ -21,15 +58,18 @@ end class Poller include Utility + include Event def initialize - @finished = false - @wait_time = Broker.poll_interval - @folder = Broker.queue + @finished = false + @wait_time = Broker.options[:poll_interval] + @folder = Broker.options[:queue] + @queue = Broker::Queue.new + @finder = Broker::Finder.new(@queue) end def terminate @finished = true if @thread @@ -44,10 +84,10 @@ def start @thread ||= safe_thread("poller") do pause_first while !@finished - puts "Checking for new files in #{@folder}" + register(@finder.check) wait end end end \ No newline at end of file