Class: SelfSDK::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/ntptime.rb

Constant Summary collapse

@@last_check =
nil

Class Method Summary collapse

Class Method Details

.nowObject

Raises:

  • (Timeout::Error)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ntptime.rb', line 12

def self.now
  timeout = 1
  ntp_time = nil
  5.times do
    begin
      ntp_time = get_ntp_current_time
      break
    rescue Timeout::Error
      puts "time.google.com timed out, retrying in #{timeout} seconds..."
      sleep timeout
      timeout = timeout+1
    end
  end
  raise Timeout::Error.new("ntp sync timed out") if ntp_time.nil?
  ntp_time
end