Class: Spider::WaitTime
- Inherits:
-
Object
- Object
- Spider::WaitTime
- Defined in:
- lib/wait_time.rb
Constant Summary collapse
- MAX_WAIT =
180- DEFAULT_WAIT =
2- REDUCE_WAIT =
300
Instance Method Summary collapse
- #back_off ⇒ Object
-
#initialize(period = nil) ⇒ WaitTime
constructor
A new instance of WaitTime.
- #reduce_wait ⇒ Object
- #value ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(period = nil) ⇒ WaitTime
Returns a new instance of WaitTime.
20 21 22 23 24 25 26 |
# File 'lib/wait_time.rb', line 20 def initialize(period=nil) unless period.nil? @wait = (period > MAX_WAIT ? MAX_WAIT : period) else @wait = DEFAULT_WAIT end end |
Instance Method Details
#back_off ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/wait_time.rb', line 28 def back_off if @wait.zero? @wait = DEFAULT_WAIT else waitval = @wait * 2 @wait = (waitval > MAX_WAIT ? MAX_WAIT : waitval) end end |
#reduce_wait ⇒ Object
41 42 43 44 |
# File 'lib/wait_time.rb', line 41 def reduce_wait sleep(REDUCE_WAIT) back_off end |
#value ⇒ Object
46 47 48 |
# File 'lib/wait_time.rb', line 46 def value @wait end |
#wait ⇒ Object
37 38 39 |
# File 'lib/wait_time.rb', line 37 def wait sleep(@wait) end |