Class: VagrantPlugins::Brightbox::Action::WaitForState
- Inherits:
-
Object
- Object
- VagrantPlugins::Brightbox::Action::WaitForState
- Defined in:
- lib/vagrant-brightbox/action/wait_for_state.rb
Overview
This action will wait for a machine to reach a specific state or quit by timeout
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env, state, timeout) ⇒ WaitForState
constructor
env will be false in case of timeout.
Constructor Details
#initialize(app, env, state, timeout) ⇒ WaitForState
env will be false in case of timeout.
12 13 14 15 16 17 |
# File 'lib/vagrant-brightbox/action/wait_for_state.rb', line 12 def initialize(app, env, state, timeout) @app = app @logger = Log4r::Logger.new("vagrant_brightbox::action::wait_for_state") @state = state @timeout = timeout end |
Instance Method Details
#call(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vagrant-brightbox/action/wait_for_state.rb', line 19 def call(env) env[:result] = true if env[:machine].state.id == @state @logger.info(I18n.t("vagrant_brightbox.already_status", :status => @state)) else @logger.info("Waiting for machine to reach state #{@state}") begin Timeout.timeout(@timeout) do until env[:machine].state.id == @state sleep 2 end end rescue Timeout::Error env[:result] = false # couldn't reach state in time end end @app.call(env) end |