diff options
author | Nikhil Benesch <nikhil.benesch@gmail.com> | 2014-03-09 22:57:21 -0400 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-05-13 15:21:15 -0700 |
commit | 89d5d20dcd494c7d42a1f24f8a3ab7712735267e (patch) | |
tree | fbcaa2b854d0dc54405485ec9fa063d52e4ad060 /lib/chef/cookbook_uploader.rb | |
parent | bea3c04f0bf8f89c637cc8073825188acb095bff (diff) | |
download | chef-89d5d20dcd494c7d42a1f24f8a3ab7712735267e.tar.gz |
CHEF-4423: extract cookbook upload threaded queue into utility class
Diffstat (limited to 'lib/chef/cookbook_uploader.rb')
-rw-r--r-- | lib/chef/cookbook_uploader.rb | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb index 6524eed3e5..968673d87a 100644 --- a/lib/chef/cookbook_uploader.rb +++ b/lib/chef/cookbook_uploader.rb @@ -7,29 +7,12 @@ require 'chef/digester' require 'chef/cookbook_version' require 'chef/cookbook/syntax_check' require 'chef/cookbook/file_system_file_vendor' +require 'chef/util/threaded_job_queue' require 'chef/sandbox' -require 'thread' class Chef class CookbookUploader - def self.work_queue - @work_queue ||= Queue.new - end - - def self.setup_worker_threads(concurrency=10) - @worker_threads ||= begin - work_queue - (1..concurrency).map do - Thread.new do - loop do - work_queue.pop.call - end - end - end - end - end - attr_reader :cookbooks attr_reader :path attr_reader :opts @@ -61,8 +44,6 @@ class Chef end def upload_cookbooks - Thread.abort_on_exception = true - # Syntax Check validate_cookbooks # generate checksums of cookbook files and create a sandbox @@ -77,7 +58,7 @@ class Chef Chef::Log.info("Uploading files") - self.class.setup_worker_threads(concurrency) + queue = Chef::Util::ThreadedJobQueue.new checksums_to_upload = Set.new @@ -86,15 +67,13 @@ class Chef if info['needs_upload'] == true checksums_to_upload << checksum Chef::Log.info("Uploading #{checksum_files[checksum]} (checksum hex = #{checksum}) to #{info['url']}") - self.class.work_queue << uploader_function_for(checksum_files[checksum], checksum, info['url'], checksums_to_upload) + queue << uploader_function_for(checksum_files[checksum], checksum, info['url'], checksums_to_upload) else Chef::Log.debug("#{checksum_files[checksum]} has not changed") end end - until checksums_to_upload.empty? - sleep 0.1 - end + queue.process(@concurrency) sandbox_url = new_sandbox['uri'] Chef::Log.debug("Committing sandbox") |