class Stackify::ScheduleDelay
Constants
- FIVE_MINUTES
- FIVE_SECONDS
- ONE_MINUTE
- ONE_SECOND
Public Class Methods
new(delay = ONE_SECOND)
click to toggle source
# File lib/stackify/schedule_delay.rb, line 9 def initialize (delay = ONE_SECOND) @delay = delay @last_http_error_occured_time = 0 end
Public Instance Methods
to_sec()
click to toggle source
# File lib/stackify/schedule_delay.rb, line 34 def to_sec @delay end
update_by_exeption!(e)
click to toggle source
# File lib/stackify/schedule_delay.rb, line 23 def update_by_exeption! e if is_authorized_exeption?(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)
click to toggle source
# 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