lib/berkshelf/installer.rb in berkshelf-3.0.0.rc1 vs lib/berkshelf/installer.rb in berkshelf-3.0.0
- old
+ new
@@ -8,11 +8,11 @@
# @param [Berkshelf::Berksfile] berksfile
def initialize(berksfile)
@berksfile = berksfile
@lockfile = berksfile.lockfile
- @downloader = Downloader.new(berksfile)
+ @worker = Worker.pool(size: [(Celluloid.cores - 1), 1].max, args: [berksfile])
end
def build_universe
berksfile.sources.collect do |source|
Thread.new do
@@ -32,14 +32,14 @@
lockfile.reduce!
Berkshelf.formatter.msg('Resolving cookbook dependencies...')
dependencies, cookbooks = if lockfile.trusted?
- install_from_lockfile
- else
- install_from_universe
- end
+ install_from_lockfile
+ else
+ install_from_universe
+ end
Berkshelf.log.debug " Finished resolving, calculating locks"
to_lock = dependencies.select do |dependency|
berksfile.has_dependency?(dependency)
@@ -57,38 +57,52 @@
cookbooks
end
private
- # Install a specific dependency.
- #
- # @param [Dependency]
- # the dependency to install
- # @return [CachedCookbook]
- # the installed cookbook
- def install(dependency)
- Berkshelf.log.info "Installing #{dependency}"
+ attr_reader :worker
- if dependency.installed?
- Berkshelf.log.debug " Already installed - skipping install"
+ class Worker
+ include Celluloid
- Berkshelf.formatter.use(dependency)
- dependency.cached_cookbook
- else
- name, version = dependency.name, dependency.locked_version.to_s
- source = berksfile.source_for(name, version)
+ attr_reader :berksfile
+ attr_reader :downloader
- Berkshelf.log.debug " Downloading #{dependency.name} (#{dependency.locked_version}) from #{source}"
+ def initialize(berksfile)
+ @berksfile = berksfile
+ @downloader = Downloader.new(berksfile)
+ end
- cookbook = source.cookbook(name, version)
+ # Install a specific dependency.
+ #
+ # @param [Dependency]
+ # the dependency to install
+ # @return [CachedCookbook]
+ # the installed cookbook
+ def install(dependency)
+ Berkshelf.log.info "Installing #{dependency}"
- Berkshelf.log.debug " => #{cookbook.inspect}"
+ if dependency.installed?
+ Berkshelf.log.debug " Already installed - skipping install"
- Berkshelf.formatter.install(source, cookbook)
+ Berkshelf.formatter.use(dependency)
+ dependency.cached_cookbook
+ else
+ name, version = dependency.name, dependency.locked_version.to_s
+ source = berksfile.source_for(name, version)
- stash = downloader.download(name, version)
- CookbookStore.import(name, version, stash)
+ Berkshelf.log.debug " Downloading #{dependency.name} (#{dependency.locked_version}) from #{source}"
+
+ cookbook = source.cookbook(name, version)
+
+ Berkshelf.log.debug " => #{cookbook.inspect}"
+
+ Berkshelf.formatter.install(source, cookbook)
+
+ stash = downloader.download(name, version)
+ CookbookStore.import(name, version, stash)
+ end
end
end
# Install all the dependencies from the lockfile graph.
#
@@ -110,13 +124,11 @@
unless dependencies.all?(&:installed?)
Berkshelf.log.debug " Not all dependencies are installed"
build_universe
end
- cookbooks = dependencies.sort.collect do |dependency|
- install(dependency)
- end
+ cookbooks = dependencies.sort.map { |dependency| worker.future.install(dependency) }.map(&:value)
[dependencies, cookbooks]
end
# Resolve and install the dependencies from the "universe", updating the
@@ -153,12 +165,10 @@
end
end
Berkshelf.log.debug " Starting resolution..."
- cookbooks = resolver.resolve.sort.collect do |dependency|
- install(dependency)
- end
+ cookbooks = resolver.resolve.sort.map { |dependency| worker.future.install(dependency) }.map(&:value)
[dependencies, cookbooks]
end
def download_locations(dependencies)