Class: CobraCommander::Executor::Concurrent

Inherits:
Object
  • Object
show all
Defined in:
lib/cobra_commander/executor/concurrent.rb

Overview

Execute a command on multiple components concurrently

Instance Method Summary collapse

Constructor Details

#initialize(components, concurrency:, spin_output:) ⇒ Concurrent

Returns a new instance of Concurrent.



10
11
12
13
14
# File 'lib/cobra_commander/executor/concurrent.rb', line 10

def initialize(components, concurrency:, spin_output:)
  @components = components
  @multi = TTY::Spinner::Multi.new(":spinner :task", output: spin_output)
  @semaphore = ::Concurrent::Semaphore.new(concurrency)
end

Instance Method Details

#exec(command) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/cobra_commander/executor/concurrent.rb', line 16

def exec(command)
  @multi.top_spinner.update(task: "Running #{command}")
  @results = []
  @components.each do |component|
    register_job(component, command)
  end
  @multi.auto_spin
  @results
end