diff options
author | John Keiser <jkeiser@opscode.com> | 2013-05-03 15:34:49 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2013-06-07 13:12:32 -0700 |
commit | 395cb75b0cd7aca6d4af27823417b247236676b9 (patch) | |
tree | 6171dfd05f64c7450c25291b296b19083250db1b /lib/chef/chef_fs/parallelizer.rb | |
parent | 001a01373ba9aed7ebec8794a31906ae21140fd6 (diff) | |
download | chef-395cb75b0cd7aca6d4af27823417b247236676b9.tar.gz |
Parallelize diff, download and upload
Diffstat (limited to 'lib/chef/chef_fs/parallelizer.rb')
-rw-r--r-- | lib/chef/chef_fs/parallelizer.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/chef/chef_fs/parallelizer.rb b/lib/chef/chef_fs/parallelizer.rb index 6aab14d7f5..e0e7a77322 100644 --- a/lib/chef/chef_fs/parallelizer.rb +++ b/lib/chef/chef_fs/parallelizer.rb @@ -2,10 +2,13 @@ class Chef module ChefFS class Parallelizer @@parallelizer = nil + @@threads = 0 def self.threads=(value) - raise "Cannot set threads after parallelize has been called" if @@parallelizer - @@threads = value + if @@threads != value + @@threads = value + @@parallelizer = nil + end end def self.parallelize(enumerator, options = {}, &block) @@ -47,13 +50,17 @@ class Chef next_index = 0 while true # Report any results that already exist - while @status.length > next_index && @status[next_index] == :finished - if @options[:flatten] - @outputs[next_index].each do |entry| - yield entry + while @status.length > next_index && ([:finished, :exception].include?(@status[next_index])) + if @status[next_index] == :finished + if @options[:flatten] + @outputs[next_index].each do |entry| + yield entry + end + else + yield @outputs[next_index] end else - yield @outputs[next_index] + raise @outputs[next_index] end next_index = next_index + 1 end @@ -84,8 +91,13 @@ class Chef [ index, input ] end - @outputs[index] = @block.call(input, @options) - @status[index] = :finished + begin + @outputs[index] = @block.call(input) + @status[index] = :finished + rescue + @outputs[index] = $! + @status[index] = :exception + end index end end |