class Gogdb::Utils

Public Class Methods

new(logger=Logger.new({})) click to toggle source
# File lib/gogdb/utils.rb, line 4
def initialize(logger=Logger.new({}))
  @logger = logger 
end

Public Instance Methods

retryConnection(url) click to toggle source

Retries connection to GOG.com incrementally (every 10n seconds, up to 120)

@params [String] @return [Boolean]

# File lib/gogdb/utils.rb, line 12
def retryConnection(url)
  @count = 1
  ph = Net::Ping::HTTP.new(url)
  
  while true do
    if ph.ping?
      @logger.warning "Connection to gog.com established successfully. Retrying previous task..."
      true
    else
      @logger.error "Cannot establish connection. Retrying in #{@count * 10} seconds..."
    end
  
    sleep(10 * @count)
    @count += 1 if @count < 12
  end
end