Class: Combi::InProcess
Constant Summary
Constants inherited from Bus
Bus::RPC_DEFAULT_TIMEOUT, Bus::RPC_MAX_POLLS
Instance Attribute Summary
Attributes inherited from Bus
Instance Method Summary collapse
- #memory_handlers ⇒ Object
- #request(handler_name, kind, message, options = {}) ⇒ Object
- #respond_to(service_instance, handler, options = {}) ⇒ Object
Methods inherited from Bus
#add_service, #enable, #initialize, #log, #post_initialize, #restart!, #start!, #stop!
Constructor Details
This class inherits a constructor from Combi::Bus
Instance Method Details
#memory_handlers ⇒ Object
40 41 42 |
# File 'lib/combi/buses/in_process.rb', line 40 def memory_handlers @memory_handlers ||= {} end |
#request(handler_name, kind, message, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/combi/buses/in_process.rb', line 6 def request(handler_name, kind, , = {}) [:timeout] ||= RPC_DEFAULT_TIMEOUT handler = memory_handlers[handler_name.to_s] return if handler.nil? service_instance = handler[:service_instance] = JSON.parse(.to_json) return unless service_instance.respond_to?(kind) waiter = EventMachine::DefaultDeferrable.new waiter.timeout([:timeout], RuntimeError.new(Timeout::Error)) begin Timeout.timeout([:timeout]) do response = service_instance.send(kind, ) if response.respond_to? :succeed response.callback do |service_response| waiter.succeed service_response end else waiter.succeed response end end rescue Timeout::Error => e log "ERROR" waiter.fail RuntimeError.new(Timeout::Error) rescue e log "other ERROR" log e.inspect end waiter end |
#respond_to(service_instance, handler, options = {}) ⇒ Object
36 37 38 |
# File 'lib/combi/buses/in_process.rb', line 36 def respond_to(service_instance, handler, = {}) memory_handlers[handler.to_s] = {service_instance: service_instance, options: } end |