Sha256: 71d61586270cc4c9bdad9b607c741307569bb4a50ae279727cf101b6d716cff2

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

class MonoRepoDeps::Task::Manager
  include MonoRepoDeps::Mixins

  Inject = MonoRepoDeps::Deps[
    packages_repo: "package.repo"
  ]

  include Inject

  sig do
    params(
      method_name: Symbol,
      args: T.anything,
      kwargs: T.anything
    )
    .void
  end
  def method_missing(method_name, *args, **kwargs)
    task = MonoRepoDeps.current_project.tasks.detect { _1.name == method_name } || (raise StandardError.new("task '#{method_name}' not found for project"))

    case task.on
    when :package
      statuses = kwargs[:packages].inject({}) do |result, package_name|
        package = packages_repo.find!(package_name.to_sym)
        result[package.name] = do_in_child(task.block, package, kwargs[:args])
        result
      end

      failed_packages = statuses.reject {|package_name, exitstatus| exitstatus.success?}

      if failed_packages.any?
        puts failed_packages.keys
        exit 1
      end
    else
      raise StandardError.new("unsupported task subject: #{task.on}")
    end
  end

  private

  def do_in_child(block, *args)
    read, write = IO.pipe

    pid = fork do
      read.close
      block.call(*args)
    end

    write.close
    Process.wait(pid)

    exit($?.exitstatus)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mono_repo_deps-0.2.0 lib/mono_repo_deps/task/manager.rb
mono_repo_deps-0.1.14 lib/mono_repo_deps/task/manager.rb
mono_repo_deps-0.1.13 lib/mono_repo_deps/task/manager.rb