Class: XmlConvApp
- Inherits:
-
SBSM::DRbServer
- Object
- SBSM::DRbServer
- XmlConvApp
- Defined in:
- lib/xmlconv/util/application.rb
Constant Summary collapse
- ENABLE_ADMIN =
true- SESSION =
XmlConv::Util::Session
- VALIDATOR =
XmlConv::Util::Validator
- POLLING_INTERVAL =
-
15
-
60
Instance Attribute Summary collapse
-
#dispatch_queue ⇒ Object
readonly
Returns the value of attribute dispatch_queue.
-
#dispatcher_thread ⇒ Object
readonly
Returns the value of attribute dispatcher_thread.
-
#polling_thread ⇒ Object
readonly
Returns the value of attribute polling_thread.
Instance Method Summary collapse
- #dispatch(transaction) ⇒ Object
- #execute_with_response(transaction) ⇒ Object
-
#initialize ⇒ XmlConvApp
constructor
A new instance of XmlConvApp.
- #start_dispatcher ⇒ Object
- #start_invoicer ⇒ Object
- #start_polling ⇒ Object
Constructor Details
#initialize ⇒ XmlConvApp
Returns a new instance of XmlConvApp.
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/xmlconv/util/application.rb', line 97 def initialize @system = ODBA.cache.fetch_named('XmlConv', self) { XmlConv::Util::Application.new } @system.init @dispatch_queue = Queue.new if(self::class::POLLING_INTERVAL) start_polling end start_dispatcher start_invoicer if XmlConv::CONFIG.run_invoicer super(@system) end |
Instance Attribute Details
#dispatch_queue ⇒ Object (readonly)
Returns the value of attribute dispatch_queue.
96 97 98 |
# File 'lib/xmlconv/util/application.rb', line 96 def dispatch_queue @dispatch_queue end |
#dispatcher_thread ⇒ Object (readonly)
Returns the value of attribute dispatcher_thread.
96 97 98 |
# File 'lib/xmlconv/util/application.rb', line 96 def dispatcher_thread @dispatcher_thread end |
#polling_thread ⇒ Object (readonly)
Returns the value of attribute polling_thread.
96 97 98 |
# File 'lib/xmlconv/util/application.rb', line 96 def polling_thread @polling_thread end |
Instance Method Details
#dispatch(transaction) ⇒ Object
110 111 112 |
# File 'lib/xmlconv/util/application.rb', line 110 def dispatch(transaction) @dispatch_queue.push(transaction) end |
#execute_with_response(transaction) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/xmlconv/util/application.rb', line 113 def execute_with_response(transaction) begin @system.execute(transaction) rescue Exception => e puts "rescued #{e.class}" end transaction.response.to_s end |
#start_dispatcher ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/xmlconv/util/application.rb', line 121 def start_dispatcher @dispatcher_thread = Thread.new { Thread.current.abort_on_exception = true loop { @system.execute(@dispatch_queue.pop) } } end |
#start_invoicer ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/xmlconv/util/application.rb', line 129 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) @system.send_invoice(strt...stop) } } end |
#start_polling ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/xmlconv/util/application.rb', line 142 def start_polling @polling_thread = Thread.new { Thread.current.abort_on_exception = true loop { begin XmlConv::Util::PollingManager.new(@system).poll_sources rescue Exception => exc XmlConv::LOGGER.error(XmlConv::CONFIG.program_name) { [exc.class, exc.].concat(exc.backtrace).join("\n") } end sleep(self::class::POLLING_INTERVAL) } } end |