Sha256: e4d69643b73d66f65f405615252257544c6f6d4837500d5040b2698e217e9ce7

Contents?: true

Size: 1.33 KB

Versions: 13

Compression:

Stored size: 1.33 KB

Contents

module DeepTest
  class Worker
    attr_reader :number

    def initialize(number, blackboard, worker_listener)
      @number = number
      @blackboard = blackboard
      @listener = worker_listener
    end

    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

    def next_work_unit
      @blackboard.take_work
    rescue Server::NoWorkUnitsAvailableError
      sleep 0.02
      retry
    end

    class Error
      attr_accessor :work_unit, :error

      def initialize(work_unit, error)
        @work_unit, @error = work_unit, error
      end

      def ==(other)
        work_unit == other.work_unit &&
            error == other.error
      end

      def to_s
        "#{@work_unit}: #{@error}\n" + (@error.backtrace || []).join("\n")
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
jason-o-matic-deep_test-1.2.2.1 lib/deep_test/worker.rb
jason-o-matic-deep_test-1.2.2.2 lib/deep_test/worker.rb
jason-o-matic-deep_test-1.2.2.3 lib/deep_test/worker.rb
jason-o-matic-deep_test-1.2.2.4 lib/deep_test/worker.rb
jperkins-deep_test-1.2.2 lib/deep_test/worker.rb
jstorimer-deep-test-1.4.0 lib/deep_test/worker.rb
jstorimer-deep-test-1.3.0 lib/deep_test/worker.rb
jstorimer-deep-test-1.2.0 lib/deep_test/worker.rb
jstorimer-deep-test-1.1.0 lib/deep_test/worker.rb
jstorimer-deep-test-1.0.0 lib/deep_test/worker.rb
deep_test-1.2.2 lib/deep_test/worker.rb
deep_test-1.2.1 lib/deep_test/worker.rb
deep_test-1.2.0 lib/deep_test/worker.rb