Allow only one Environment#batch to run at a time per env
This commit is contained in:
parent
df93a221e1
commit
368dddd950
|
@ -2,6 +2,7 @@ require 'fileutils'
|
|||
require 'json'
|
||||
require 'pathname'
|
||||
require 'set'
|
||||
require 'thread'
|
||||
|
||||
require 'log4r'
|
||||
|
||||
|
@ -95,6 +96,10 @@ module Vagrant
|
|||
@ui = opts[:ui_class].new
|
||||
@ui_class = opts[:ui_class]
|
||||
|
||||
# This is the batch lock, that enforces that only one {BatchAction}
|
||||
# runs at a time from {#batch}.
|
||||
@batch_lock = Mutex.new
|
||||
|
||||
@lock_acquired = false
|
||||
|
||||
@logger = Log4r::Logger.new("vagrant::environment")
|
||||
|
@ -194,12 +199,14 @@ module Vagrant
|
|||
# This handles the case where batch actions are disabled by the
|
||||
# VAGRANT_NO_PARALLEL environmental variable.
|
||||
def batch
|
||||
BatchAction.new(!!ENV["VAGRANT_NO_PARALLEL"]).tap do |b|
|
||||
# Yield it so that the caller can setup actions
|
||||
yield b
|
||||
@batch_lock.synchronize do
|
||||
BatchAction.new(!!ENV["VAGRANT_NO_PARALLEL"]).tap do |b|
|
||||
# Yield it so that the caller can setup actions
|
||||
yield b
|
||||
|
||||
# And run it!
|
||||
b.run
|
||||
# And run it!
|
||||
b.run
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue