Class: Verifalia::EmailValidations::WaitOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/verifalia/email_validation/wait_options.rb

Constant Summary collapse

@@default =
nil
@@no_wait =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(submission_wait_time, poll_wait_time, progress: nil) ⇒ WaitOptions

Returns a new instance of WaitOptions.



40
41
42
43
44
# File 'lib/verifalia/email_validation/wait_options.rb', line 40

def initialize(submission_wait_time, poll_wait_time, progress: nil)
  @submission_wait_time = submission_wait_time
  @poll_wait_time = poll_wait_time
  @progress = progress
end

Instance Attribute Details

#poll_wait_timeObject (readonly)

Returns the value of attribute poll_wait_time.



38
39
40
# File 'lib/verifalia/email_validation/wait_options.rb', line 38

def poll_wait_time
  @poll_wait_time
end

#progressObject (readonly)

Returns the value of attribute progress.



38
39
40
# File 'lib/verifalia/email_validation/wait_options.rb', line 38

def progress
  @progress
end

#submission_wait_timeObject (readonly)

Returns the value of attribute submission_wait_time.



38
39
40
# File 'lib/verifalia/email_validation/wait_options.rb', line 38

def submission_wait_time
  @submission_wait_time
end

Class Method Details

.defaultObject



46
47
48
49
# File 'lib/verifalia/email_validation/wait_options.rb', line 46

def self.default
  @@default = WaitOptions.new 30 * 1000, 30 * 1000 if @@default.nil?
  @@default
end

.no_waitObject



51
52
53
54
# File 'lib/verifalia/email_validation/wait_options.rb', line 51

def self.no_wait
  @@no_wait = WaitOptions.new 0, 0 if @@no_wait.nil?
  @@no_wait
end

Instance Method Details

#wait_for_next_poll(job) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/verifalia/email_validation/wait_options.rb', line 56

def wait_for_next_poll(job)
  # Observe the ETA if we have one, otherwise a delay given the following formula:
  # delay = max(0.5, min(30, 2^(log(noOfEntries, 10) - 1)))

  if !job.overview.progress.nil? && !job.overview.progress.estimated_time_remaining.nil?
    # Convert the ETA format (dd.)HH:mm:ss into the number of remaining seconds

    eta_match = /((\d*)\.)?(\d{1,2}):(\d{1,2}):(\d{1,2})/.match(job.overview.progress.estimated_time_remaining)

    days = (eta_match[2] || '0').to_i
    hours = eta_match[3].to_i
    minutes = eta_match[4].to_i
    seconds = eta_match[5].to_i

    delay = days * 24 * 60 * 60 +
            hours * 60 * 60 +
            minutes * 60 +
            seconds
  else
    delay = [0.5, [30, 2**(Math.log10(job.overview.no_of_entries) - 1)].min].max
  end

  sleep(delay)
end