lib/berkshelf/installer.rb in berkshelf-6.0.1 vs lib/berkshelf/installer.rb in berkshelf-6.1.0
- old
+ new
@@ -1,6 +1,8 @@
require "berkshelf/api-client"
+require "concurrent/executors"
+require "concurrent/future"
module Berkshelf
class Installer
attr_reader :berksfile
attr_reader :lockfile
@@ -8,18 +10,19 @@
# @param [Berkshelf::Berksfile] berksfile
def initialize(berksfile)
@berksfile = berksfile
@lockfile = berksfile.lockfile
- @worker = Worker.pool(size: [(Celluloid.cores.to_i - 1), 2].max, args: [berksfile])
+ @pool = Concurrent::FixedThreadPool.new([Concurrent.processor_count - 1, 2].max)
+ @worker = Worker.new(berksfile)
end
def build_universe
berksfile.sources.collect do |source|
Thread.new do
begin
- Berkshelf.formatter.msg("Fetching cookbook index from #{source.uri}...")
+ Berkshelf.formatter.msg("Fetching cookbook index from #{source}...")
source.build_universe
rescue Berkshelf::APIClientError => ex
Berkshelf.formatter.warn "Error retrieving universe from source: #{source}"
Berkshelf.formatter.warn " * [#{ex.class}] #{ex}"
end
@@ -59,14 +62,13 @@
end
private
attr_reader :worker
+ attr_reader :pool
class Worker
- include Celluloid
-
attr_reader :berksfile
attr_reader :downloader
def initialize(berksfile)
@berksfile = berksfile
@@ -130,11 +132,14 @@
unless dependencies.all?(&:installed?)
Berkshelf.log.debug " Not all dependencies are installed"
build_universe
end
- cookbooks = dependencies.sort.map { |dependency| worker.future.install(dependency) }.map(&:value)
+ futures = dependencies.sort.map { |dependency| Concurrent::Future.execute(executor: pool) { worker.install(dependency) } }
+ cookbooks = futures.map(&:value)
+ rejects = futures.select(&:rejected?)
+ raise rejects.first.reason unless rejects.empty?
[dependencies, cookbooks]
end
# Resolve and install the dependencies from the "universe", updating the
@@ -171,10 +176,13 @@
end
end
Berkshelf.log.debug " Starting resolution..."
- cookbooks = resolver.resolve.sort.map { |dependency| worker.future.install(dependency) }.map(&:value)
+ futures = resolver.resolve.sort.map { |dependency| Concurrent::Future.execute(executor: pool) { worker.install(dependency) } }
+ cookbooks = futures.map(&:value)
+ rejects = futures.select(&:rejected?)
+ raise rejects.first.reason unless rejects.empty?
[dependencies, cookbooks]
end
def download_locations(dependencies)