Class: DeepTest::Distributed::DispatchController
- Inherits:
-
Object
- Object
- DeepTest::Distributed::DispatchController
- Defined in:
- lib/deep_test/distributed/dispatch_controller.rb
Instance Method Summary collapse
- #description(receiver) ⇒ Object
- #dispatch(method_name, *args) ⇒ Object
- #dispatch_with_options(method_name, options, *args) ⇒ Object
-
#initialize(options, receivers) ⇒ DispatchController
constructor
A new instance of DispatchController.
Constructor Details
#initialize(options, receivers) ⇒ DispatchController
Returns a new instance of DispatchController.
4 5 6 7 |
# File 'lib/deep_test/distributed/dispatch_controller.rb', line 4 def initialize(, receivers) @options = @receivers = receivers end |
Instance Method Details
#description(receiver) ⇒ Object
52 53 54 |
# File 'lib/deep_test/distributed/dispatch_controller.rb', line 52 def description(receiver) receiver.inspect end |
#dispatch(method_name, *args) ⇒ Object
9 10 11 |
# File 'lib/deep_test/distributed/dispatch_controller.rb', line 9 def dispatch(method_name, *args) (method_name, {}, *args) end |
#dispatch_with_options(method_name, options, *args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/deep_test/distributed/dispatch_controller.rb', line 13 def (method_name, , *args) raise NoDispatchReceiversError if @receivers.empty? @options.ui_instance.dispatch_starting(method_name) threads = @receivers.map do |r| Thread.new do begin Thread.current[:receiver] = r r.send method_name, *args rescue Exception => e Thread.current[:original_exception] = e raise end end end results = [] threads.each do |t| begin results << t.value rescue Timeout::Error @receivers.delete t[:receiver] DeepTest.logger.error { "Timeout dispatching #{method_name} to #{description t[:receiver]}" } rescue Exception => this_exception @receivers.delete t[:receiver] DeepTest.logger.error { "Exception while dispatching #{method_name} to #{description t[:receiver]}:" } e = t[:original_exception] || this_exception DeepTest.logger.error { "#{e.class}: #{e.}" } e.backtrace.each {|l| DeepTest.logger.error { l } } end end results ensure @options.ui_instance.dispatch_finished(method_name) end |