Class: Stackify::ScheduleDelay
Constant Summary collapse
- ONE_SECOND =
1.0- ONE_MINUTE =
60.0- FIVE_SECONDS =
5.0- FIVE_MINUTES =
300.0
Instance Method Summary collapse
-
#initialize(delay = ONE_SECOND) ⇒ ScheduleDelay
constructor
A new instance of ScheduleDelay.
- #to_sec ⇒ Object
- #update_by_exeption!(e) ⇒ Object
- #update_by_sent_num!(num_sent) ⇒ Object
Constructor Details
#initialize(delay = ONE_SECOND) ⇒ ScheduleDelay
Returns a new instance of ScheduleDelay.
9 10 11 12 |
# File 'lib/stackify/schedule_delay.rb', line 9 def initialize (delay = ONE_SECOND) @delay = delay @last_http_error_occured_time = 0 end |
Instance Method Details
#to_sec ⇒ Object
34 35 36 |
# File 'lib/stackify/schedule_delay.rb', line 34 def to_sec @delay end |
#update_by_exeption!(e) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stackify/schedule_delay.rb', line 23 def update_by_exeption! e if (e) @last_http_error_occured_time = Time.now if @last_http_error_occured_time == 0 since_first_error = (Time.now - @last_http_error_occured_time).round(2) @delay = [[since_first_error, ONE_SECOND].max, ONE_MINUTE].min else @last_http_error_occured_time = Time.now @delay = FIVE_MINUTES end end |
#update_by_sent_num!(num_sent) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/stackify/schedule_delay.rb', line 14 def update_by_sent_num! num_sent @last_http_error_occured_time = 0 if num_sent >= 100 @delay = [(@delay/ 2.0).round(2), ONE_SECOND].max elsif num_sent < 10 @delay = [(@delay * 1.25).round(2), FIVE_SECONDS].min end end |