/usr/share/pyshared/pika/reconnection_strategies.py is in python-pika 0.9.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | # ***** BEGIN LICENSE BLOCK *****
#
# For copyright and licensing please refer to COPYING.
#
# ***** END LICENSE BLOCK *****
from pika.log import info
from random import random
class ReconnectionStrategy(object):
can_reconnect = False
def on_connect_attempt(self, conn):
pass
def on_connect_attempt_failure(self, conn):
pass
def on_transport_connected(self, conn):
pass
def on_transport_disconnected(self, conn):
pass
def on_connection_open(self, conn):
pass
def on_connection_closed(self, conn):
pass
class NullReconnectionStrategy(ReconnectionStrategy):
pass
class SimpleReconnectionStrategy(ReconnectionStrategy):
can_reconnect = True
def __init__(self, initial_retry_delay=1.0, multiplier=2.0,
max_delay=30.0, jitter=0.5):
self.initial_retry_delay = initial_retry_delay
self.multiplier = multiplier
self.max_delay = max_delay
self.jitter = jitter
self._reset()
def _reset(self):
self.current_delay = self.initial_retry_delay
self.attempts_since_last_success = 0
def on_connect_attempt(self, conn):
self.attempts_since_last_success += 1
def on_connection_open(self, conn):
self._reset()
def on_connection_closed(self, conn):
t = self.current_delay * ((random() * self.jitter) + 1)
info("%s retrying %r in %r seconds (%r attempts)",
self.__class__.__name__, conn.parameters, t,
self.attempts_since_last_success)
self.current_delay = min(self.max_delay,
self.current_delay * self.multiplier)
conn.add_timeout(t, conn._reconnect)
|