Class: PDK::CLI::ParallelExecGroup

Inherits:
ExecGroup
  • Object
show all
Defined in:
lib/pdk/cli/exec_group.rb

Overview

Executes registered blocks in parallel using Ruby threads

See Also:

Instance Method Summary collapse

Methods inherited from ExecGroup

create

Constructor Details

#initialize(message, opts = {}) ⇒ ParallelExecGroup

Returns a new instance of ParallelExecGroup.



77
78
79
80
81
# File 'lib/pdk/cli/exec_group.rb', line 77

def initialize(message, opts = {})
  super(message, opts)
  @threads = []
  @exit_codes = []
end

Instance Method Details

#exit_codeObject



97
98
99
100
101
# File 'lib/pdk/cli/exec_group.rb', line 97

def exit_code
  @threads.each(&:join)
  return 0 if @exit_codes.empty?
  @exit_codes.max
end

#register(&block) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/pdk/cli/exec_group.rb', line 83

def register(&block)
  super(&block)

  # TODO: This executes the thread immediately, whereas the SerialExecGroup executes only when exit_code
  # is called.  Need to change this so it uses a kind of ThreadPool to limit to number on concurrent jobs
  # and only starts on the call to exit_code
  # e.g. max_threads = No. of CPUs
  @threads << Thread.new do
    GettextSetup.initialize(File.absolute_path('../../../locales', File.dirname(__FILE__)))
    GettextSetup.negotiate_locale!(GettextSetup.candidate_locales)
    @exit_codes << yield
  end
end