Permalink
Browse files

Merge "Use thread pool to run stop_instances."

  • Loading branch information...
2 parents 883b598 + 3e97489 commit 478ee10a6f5f81c9896849a6282c452203807f16 felixhoo committed with Gerrit Code Review Jan 7, 2013
Showing with 6 additions and 15 deletions.
  1. +6 −15 lib/base/warden/node_utils.rb
@@ -206,22 +206,13 @@ def stop_all_instances
end
def stop_instances(all_instances)
- @instance_parallel_stop_count = 10 if @instance_parallel_stop_count.nil?
- start = 0
- while start < all_instances.size
- instances = all_instances.slice(start, [@instance_parallel_stop_count, all_instances.size - start].min)
- start = start + @instance_parallel_stop_count
- threads = (1..instances.size).collect do |i|
- Thread.new(instances[i - 1]) do |t_instance|
- begin
- t_instance.stop
- @logger.info("Successfully stop instance #{t_instance.name}")
- rescue => e
- @logger.error("Error stopping instance #{t_instance.name}: #{e}")
- end
- end
+ pool_run(all_instances, @instance_parallel_stop_count || 10) do |instance|
+ begin
+ instance.stop
+ @logger.info("Successfully stop instance #{instance.name}")
+ rescue => e
+ @logger.error("Error stopping instance #{instance.name}: #{e}")
end
- threads.each {|t| t.join}
end
end

0 comments on commit 478ee10

Please sign in to comment.