Module: Masamune::Actions::InvokeParallel

Extended by:
ActiveSupport::Concern
Includes:
Execute
Defined in:
lib/masamune/actions/invoke_parallel.rb

Instance Method Summary collapse

Methods included from Execute

#execute

Instance Method Details

#invoke_parallel(*task_group) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/masamune/actions/invoke_parallel.rb', line 37

def invoke_parallel(*task_group)
  per_task_opts = task_group.last.is_a?(Array) ? task_group.pop.dup : [{}]
  all_task_opts = task_group.last.is_a?(Hash) ? task_group.pop.dup : {}
  task_group_by_task_opts = task_group.product(per_task_opts)
  max_tasks = [all_task_opts.delete(:max_tasks), task_group_by_task_opts.count].min
  console("Setting max_tasks to #{max_tasks}")
  bail_fast task_group, all_task_opts if all_task_opts[:version]
  Parallel.each(task_group_by_task_opts, in_processes: max_tasks) do |task_name, task_opts|
    task_env = task_opts[:env] || {}
    begin
      execute(thor_wrapper, task_name, *task_args(all_task_opts.merge(task_opts)), interactive: true, detach: false, env: task_env)
    rescue SystemExit # rubocop:disable Lint/HandleExceptions
    end
  end
end