class XmlConvApp
Constants
- POLLING_INTERVAL
Attributes
app[R]
dispatch_queue[R]
dispatcher_thread[R]
persistence_layer[R]
polling_thread[R]
Public Class Methods
new(app: XmlConv::Util::RackInterface.new)
click to toggle source
Calls superclass method
# File lib/xmlconv/util/application.rb, line 131 def initialize(app: XmlConv::Util::RackInterface.new) @rack_app = app super(app: app) # TODO?? , multi_threaded: true) @persistence_layer = ODBA.cache.fetch_named('XmlConv', self) do XmlConv::Util::Application.new end @persistence_layer.init @dispatch_queue = Queue.new @polling_interval = XmlConv::CONFIG.polling_interval || self::class::POLLING_INTERVAL puts "@polling_interval is #{@polling_interval} @persistence_layer is #{@persistence_layer.class}" start_polling if @polling_interval start_dispatcher start_invoicer if XmlConv::CONFIG.run_invoicer end
Public Instance Methods
dispatch(transaction)
click to toggle source
# File lib/xmlconv/util/application.rb, line 143 def dispatch(transaction) @dispatch_queue.push(transaction) end
execute_with_response(transaction)
click to toggle source
# File lib/xmlconv/util/application.rb, line 146 def execute_with_response(transaction) begin @persistence_layer.execute(transaction) rescue Exception => e puts "rescued #{e.class}" end transaction.response.to_s end
start_dispatcher()
click to toggle source
# File lib/xmlconv/util/application.rb, line 154 def start_dispatcher @dispatcher_thread = Thread.new { Thread.current.abort_on_exception = true loop { @persistence_layer.execute(@dispatch_queue.pop) } } end
start_invoicer()
click to toggle source
# File lib/xmlconv/util/application.rb, line 162 def start_invoicer @invoicer_thread = Thread.new { Thread.current.abort_on_exception = true loop { this_month = Date.today next_month = this_month >> 1 strt = Time.local(this_month.year, this_month.month) stop = Time.local(next_month.year, next_month.month) sleep(stop - Time.now) @persistence_layer.send_invoice(strt...stop) } } end
start_polling()
click to toggle source
# File lib/xmlconv/util/application.rb, line 175 def start_polling @polling_thread = Thread.new { Thread.current.abort_on_exception = true loop { begin XmlConv::Util::PollingManager.new(@persistence_layer).poll_sources rescue Exception => exc SBSM.logger.error(XmlConv::CONFIG.program_name) { [exc.class, exc.message].concat(exc.backtrace).join("\n") } end sleep(@polling_interval) } } end