Module: CobraCommander::Executor

Defined in:
lib/cobra_commander/executor.rb,
lib/cobra_commander/executor/script.rb,
lib/cobra_commander/executor/command.rb,
lib/cobra_commander/executor/run_script.rb,
lib/cobra_commander/executor/worker_pool.rb,
lib/cobra_commander/executor/isolated_pty.rb,
lib/cobra_commander/executor/output_prompt.rb,
lib/cobra_commander/executor/buffered_printer.rb,
lib/cobra_commander/executor/package_criteria.rb

Overview

Execute a command on all given packages

Defined Under Namespace

Modules: PackageCriteria, RunScript Classes: BufferedPrinter, Command, IsolatedPTY, OutputPrompt, Script, WorkerPool

Class Method Summary collapse

Class Method Details

.execute_and_handle_exit(jobs:, interactive: false, **kwargs, &name_f) ⇒ Object

Executes the given jobs in an CobraCommander::Executor::WorkerPool.

When only one job is queued, it choses the :quiet printer, to print the output as it happens. When more than one job is queued in interactive mode, it uses the :progress printer, which will display a green dot or a red F depending on the result of each script execution. If not in interactive mode, it will print the output in a buffered way to make it easier to read each output.

Parameters:

  • jobs (Enumerable<CobraCommander::Executor::Job>)

    the jobs to run

  • interactive (Boolean) (defaults to: false)

    prefer interactive output

See Also:



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cobra_commander/executor.rb', line 35

def execute_and_handle_exit(jobs:, interactive: false, **kwargs, &name_f)
  printer = if jobs.size == 1 then :quiet
            elsif interactive then :progress
            else
              ::CobraCommander::Executor::BufferedPrinter
            end
  pool = WorkerPool.new(jobs: jobs, printer: printer, **kwargs, &name_f).tap(&:start)
  return CobraCommander::Executor::OutputPrompt.run(pool) if interactive && jobs.size > 1

  exit(1) if pool.error?
end