Class: Flatware::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/flatware/worker.rb

Overview

executes tests and sends results to the sink

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, runner, sink_endpoint) ⇒ Worker

Returns a new instance of Worker.



11
12
13
14
15
16
# File 'lib/flatware/worker.rb', line 11

def initialize(id, runner, sink_endpoint)
  @id       = id
  @runner   = runner
  @sink     = DRbObject.new_with_uri sink_endpoint
  Flatware::Sink.client = @sink
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/flatware/worker.rb', line 9

def id
  @id
end

#runnerObject (readonly)

Returns the value of attribute runner.



9
10
11
# File 'lib/flatware/worker.rb', line 9

def runner
  @runner
end

#sinkObject (readonly)

Returns the value of attribute sink.



9
10
11
# File 'lib/flatware/worker.rb', line 9

def sink
  @sink
end

Class Method Details

.spawn(count:, runner:, sink:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/flatware/worker.rb', line 18

def self.spawn(count:, runner:, sink:, **)
  Flatware.configuration.before_fork.call
  count.times do |i|
    fork do
      $0 = "flatware worker #{i}"
      ENV['TEST_ENV_NUMBER'] = i.to_s
      Flatware.configuration.after_fork.call(i)
      new(i, runner, sink).listen
    end
  end
end

Instance Method Details

#listenObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/flatware/worker.rb', line 30

def listen
  retrying(times: 10, wait: 0.1) do
    job = sink.ready id
    until want_to_quit? || job.sentinel?
      job.worker = id
      sink.started job
      run job
      job = sink.ready id
    end
  end
end