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.
19 20 21 22 23 24 25 |
# 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 |
Instance Method Details
#back_off ⇒ Object
27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
40 41 42 43 |
# File 'lib/wait_time.rb', line 40 def reduce_wait sleep(REDUCE_WAIT) back_off end |
#value ⇒ Object
45 46 47 |
# File 'lib/wait_time.rb', line 45 def value @wait end |
#wait ⇒ Object
36 37 38 |
# File 'lib/wait_time.rb', line 36 def wait sleep(@wait) end |