module OpsManagerUiDrivers::WaitHelper
Constants
- EarlyFailException
- SLEEP_INTERVAL
Public Instance Methods
fail_early(msg)
click to toggle source
# File lib/ops_manager_ui_drivers/wait_helper.rb, line 11 def fail_early(msg) fail(EarlyFailException.new(msg)) end
poll_up_to_mins(minutes, sleep_interval = SLEEP_INTERVAL, &blk)
click to toggle source
# File lib/ops_manager_ui_drivers/wait_helper.rb, line 15 def poll_up_to_mins(minutes, sleep_interval = SLEEP_INTERVAL, &blk) title = "Polling for #{minutes} mins" Logger.debug "--- BEGIN #{title}" retry_until(minutes_to_time(minutes), sleep_interval, &blk) ensure Logger.debug "--- END #{title}" end
poll_up_to_times(times, sleep_interval = SLEEP_INTERVAL, &blk)
click to toggle source
# File lib/ops_manager_ui_drivers/wait_helper.rb, line 24 def poll_up_to_times(times, sleep_interval = SLEEP_INTERVAL, &blk) title = "Polling for #{times} times" Logger.debug "--- BEGIN #{title}" retry_times(times, sleep_interval, &blk) ensure Logger.debug "--- END #{title}" end
Private Instance Methods
minutes_to_time(minutes)
click to toggle source
# File lib/ops_manager_ui_drivers/wait_helper.rb, line 74 def minutes_to_time(minutes) Time.now + (minutes * 60) end
retry_times(retries, sleep_interval, &blk)
click to toggle source
We're rescuing StandardError because Capybara throws random stuff at us.
# File lib/ops_manager_ui_drivers/wait_helper.rb, line 37 def retry_times(retries, sleep_interval, &blk) blk.call rescue EarlyFailException raise rescue RSpec::Expectations::ExpectationNotMetError, StandardError => e retries -= 1 Logger.debug "------- retries_left=#{retries}" if retries > 0 sleep(sleep_interval) retry else Logger.debug "------- propagate error=#{e}" raise end end
retry_until(end_time, sleep_interval, &blk)
click to toggle source
# File lib/ops_manager_ui_drivers/wait_helper.rb, line 53 def retry_until(end_time, sleep_interval, &blk) blk.call rescue EarlyFailException raise rescue RSpec::Expectations::ExpectationNotMetError, StandardError => e seconds_left = (end_time - Time.now).round last_logged_at ||= 1.seconds.ago if seconds_left % 10 == 0 && (Time.now - last_logged_at).round != 0 Logger.debug "------- seconds_left=#{seconds_left}" end if seconds_left > sleep_interval sleep(sleep_interval) retry else Logger.debug "------- propagate error=#{e}" raise end end