Sha256: ba2071fe605c5c0730dec505ec7046a7e0393759c688ee6e1604387ad43738c9
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 KB
Contents
module EventMachine module Twitter module Reconnectors class NetworkFailure START = 0.25 INCREMENTOR = 0.25 MAX = 16 MAX_RECONNECTS = 10 DEFAULT_RECONNECT = 0 MAX_TIMEOUT = 320 attr_reader :reconnect_count attr_writer :reconnect_timeout def initialize(options = {}) @reconnect_timeout = options.delete(:reconnect_timeout) || START @reconnect_count = options.delete(:reconnect_count) || DEFAULT_RECONNECT end def reconnect_timeout [@reconnect_timeout, MAX].min end def increment @reconnect_count += 1 @reconnect_timeout += INCREMENTOR if maximum_reconnects? raise EM::Twitter::ReconnectLimitError.new("#{@reconnect_count} Reconnects") end yield @reconnect_timeout if block_given? end def reset @reconnect_timeout = START @reconnect_count = DEFAULT_RECONNECT end private def maximum_reconnects? @reconnect_count > MAX_RECONNECTS || @reconnect_timeout > MAX_TIMEOUT end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
em-twitter-0.1.1 | lib/em-twitter/reconnectors/network_failure.rb |
em-twitter-0.1.0 | lib/em-twitter/reconnectors/network_failure.rb |