class Spider::WaitTime

Constants

DEFAULT_WAIT
MAX_WAIT
REDUCE_WAIT

Public Class Methods

new(period = nil) click to toggle source
# File lib/wait_time.rb, line 19
def initialize(period = nil)
  if period.nil?
    @wait = DEFAULT_WAIT
  else
    @wait = (period > MAX_WAIT ? MAX_WAIT : period)
  end
end

Public Instance Methods

back_off() click to toggle source
# File lib/wait_time.rb, line 27
def back_off
  if @wait.zero?
    @wait = DEFAULT_WAIT
  else
    waitval = @wait * 2
    @wait = (waitval > MAX_WAIT ? MAX_WAIT : waitval)
  end
end
reduce_wait() click to toggle source
# File lib/wait_time.rb, line 40
def reduce_wait
  sleep(REDUCE_WAIT)
  back_off
end
value() click to toggle source
# File lib/wait_time.rb, line 45
def value
  @wait
end
wait() click to toggle source
# File lib/wait_time.rb, line 36
def wait
  sleep(@wait)
end