Class: GDK::TestURL
- Inherits:
-
Object
- Object
- GDK::TestURL
- Defined in:
- lib/gdk/test_url.rb
Constant Summary collapse
- MAX_ATTEMPTS =
90- SLEEP_BETWEEN_ATTEMPTS =
3- OPEN_TIMEOUT =
60- READ_TIMEOUT =
60- UrlAppearsInvalid =
Class.new(StandardError)
Class Method Summary collapse
Instance Method Summary collapse
- #check_url(verbose: false, silent: false) ⇒ Object
- #check_url_oneshot(verbose: false, silent: true) ⇒ Object
-
#initialize(url = self.class.default_url, max_attempts: MAX_ATTEMPTS, sleep_between_attempts: SLEEP_BETWEEN_ATTEMPTS, read_timeout: READ_TIMEOUT, open_timeout: OPEN_TIMEOUT) ⇒ TestURL
constructor
A new instance of TestURL.
- #wait(verbose: false) ⇒ Object
Constructor Details
#initialize(url = self.class.default_url, max_attempts: MAX_ATTEMPTS, sleep_between_attempts: SLEEP_BETWEEN_ATTEMPTS, read_timeout: READ_TIMEOUT, open_timeout: OPEN_TIMEOUT) ⇒ TestURL
Returns a new instance of TestURL.
18 19 20 21 22 23 24 25 26 |
# File 'lib/gdk/test_url.rb', line 18 def initialize(url = self.class.default_url, max_attempts: MAX_ATTEMPTS, sleep_between_attempts: SLEEP_BETWEEN_ATTEMPTS, read_timeout: READ_TIMEOUT, open_timeout: OPEN_TIMEOUT) raise UrlAppearsInvalid unless URI::DEFAULT_PARSER.make_regexp.match?(url) @uri = URI.parse(url) @max_attempts = max_attempts @sleep_between_attempts = sleep_between_attempts @read_timeout = read_timeout @open_timeout = open_timeout end |
Class Method Details
Instance Method Details
#check_url(verbose: false, silent: false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gdk/test_url.rb', line 44 def check_url(verbose: false, silent: false) result = false display_output = verbose && !silent 1.upto(max_attempts) do |i| GDK::Output.puts("\n> Testing GDK attempt ##{i}..") if display_output if check_url_oneshot(verbose: verbose, silent: silent) result = true break end sleep(sleep_between_attempts) end result end |
#check_url_oneshot(verbose: false, silent: true) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gdk/test_url.rb', line 62 def check_url_oneshot(verbose: false, silent: true) display_output = verbose && !silent if http_helper.head_up? GDK::Output.puts("#{http_helper.last_response_reason}\n") if display_output GDK::Output.puts unless silent return true end if display_output GDK::Output.puts(http_helper.last_response_reason) elsif !silent GDK::Output.print('.') end false end |
#wait(verbose: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gdk/test_url.rb', line 28 def wait(verbose: false) @start_time = Time.now = GDK::Output.notice_format("Waiting until #{uri} is ready..") verbose ? GDK::Output.puts() : GDK::Output.print() if check_url(verbose: verbose) GDK::Output.notice("#{uri} is up (#{http_helper.last_response_reason}). Took #{duration} second(s).") store_gitlab_commit_sha true else GDK::Output.notice("#{uri} does not appear to be up. Waited #{duration} second(s).") false end end |