Class: DeepTest::Worker
- Inherits:
-
Object
- Object
- DeepTest::Worker
- Defined in:
- lib/deep_test/worker.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
-
#initialize(number, blackboard, worker_listener) ⇒ Worker
constructor
A new instance of Worker.
- #next_work_unit ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(number, blackboard, worker_listener) ⇒ Worker
Returns a new instance of Worker.
5 6 7 8 9 |
# File 'lib/deep_test/worker.rb', line 5 def initialize(number, blackboard, worker_listener) @number = number @blackboard = blackboard @listener = worker_listener end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/deep_test/worker.rb', line 3 def number @number end |
Instance Method Details
#next_work_unit ⇒ Object
33 34 35 36 37 38 |
# File 'lib/deep_test/worker.rb', line 33 def next_work_unit @blackboard.take_work rescue Server::NoWorkUnitsAvailableError sleep 0.02 retry end |
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/deep_test/worker.rb', line 11 def run @listener.starting(self) while work_unit = next_work_unit @listener.starting_work(self, work_unit) result = begin work_unit.run rescue Exception => error Error.new(work_unit, error) end @listener.finished_work(self, work_unit, result) @blackboard.write_result result if ENV['DEEP_TEST_SHOW_WORKER_DOTS'] == 'yes' $stdout.print '.' $stdout.flush end end rescue Server::NoWorkUnitsRemainingError DeepTest.logger.debug("Worker #{number}: no more work to do") end |