Class: Racecar::ParallelRunner
- Inherits:
-
Object
- Object
- Racecar::ParallelRunner
- Defined in:
- lib/racecar/parallel_runner.rb
Defined Under Namespace
Classes: Worker
Constant Summary collapse
- SHUTDOWN_SIGNALS =
["INT", "QUIT", "TERM"]
Instance Method Summary collapse
-
#initialize(runner:, config:, logger:) ⇒ ParallelRunner
constructor
A new instance of ParallelRunner.
- #run ⇒ Object
- #running? ⇒ Boolean
- #stop ⇒ Object
- #worker_pids ⇒ Object
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
#run ⇒ Object
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
19 20 21 |
# File 'lib/racecar/parallel_runner.rb', line 19 def running? @running end |
#stop ⇒ Object
40 41 42 |
# File 'lib/racecar/parallel_runner.rb', line 40 def stop terminate_workers end |
#worker_pids ⇒ Object
15 16 17 |
# File 'lib/racecar/parallel_runner.rb', line 15 def worker_pids workers.map(&:pid) end |