Class: Racecar::ParallelRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/racecar/parallel_runner.rb

Defined Under Namespace

Classes: Worker

Constant Summary collapse

SHUTDOWN_SIGNALS =
["INT", "QUIT", "TERM"]

Instance Method Summary collapse

Constructor Details

#initialize(runner:, config:, logger:) ⇒ ParallelRunner

Returns a new instance of ParallelRunner.



9
10
11
12
13
# File 'lib/racecar/parallel_runner.rb', line 9

def initialize(runner:, config:, logger:)
  @runner = runner
  @config = config
  @logger = logger
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/racecar/parallel_runner.rb', line 23

def run
  logger.info "=> Running with #{config.parallel_workers} parallel workers"

  self.workers = config.parallel_workers.times.map do
    run_worker.tap { |w| logger.info "=> Forked new Racecar consumer with process id #{w.pid}" }
  end

  # Print the consumer config to STDERR on USR1.
  trap("USR1") { $stderr.puts config.inspect }

  SHUTDOWN_SIGNALS.each { |signal| trap(signal) { terminate_workers } }

  @running = true

  wait_for_exit
end

#running?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/racecar/parallel_runner.rb', line 19

def running?
  @running
end

#worker_pidsObject



15
16
17
# File 'lib/racecar/parallel_runner.rb', line 15

def worker_pids
  workers.map(&:pid)
end