Skip to content
Snippets Groups Projects
Commit 5df95cd9 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

ConnectionUp will tell if this is a first connect or a reconnect

parent 3e537c8e
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,9 @@ class ConnectionDown(ClusterEvent): ...@@ -14,6 +14,9 @@ class ConnectionDown(ClusterEvent):
class ConnectionUp(ClusterEvent): class ConnectionUp(ClusterEvent):
"""Connection to broker has been (re)established""" """Connection to broker has been (re)established"""
def __init__(self, initial=False):
self.initial = initial #: public, is this first connection up in this cluster ever?
class MessageReceived(ClusterEvent): class MessageReceived(ClusterEvent):
"""A message has been received from the broker""" """A message has been received from the broker"""
......
...@@ -33,6 +33,7 @@ class ClusterHandlerThread(threading.Thread): ...@@ -33,6 +33,7 @@ class ClusterHandlerThread(threading.Thread):
self.queues_by_consumer_tags = {} # listened queues, by their consumer tags self.queues_by_consumer_tags = {} # listened queues, by their consumer tags
self.backend = None self.backend = None
self.first_connect = True
def _reconnect(self): def _reconnect(self):
exponential_backoff_delay = 1 exponential_backoff_delay = 1
...@@ -80,7 +81,8 @@ class ClusterHandlerThread(threading.Thread): ...@@ -80,7 +81,8 @@ class ClusterHandlerThread(threading.Thread):
exponential_backoff_delay = 60 exponential_backoff_delay = 60
else: else:
self.cluster.connected = True self.cluster.connected = True
self.event_queue.put(ConnectionUp()) self.event_queue.put(ConnectionUp(initial=self.first_connect))
self.first_connect = False
break # we connected :) break # we connected :)
......
...@@ -6,7 +6,7 @@ QUEUE_NAME = 'f' ...@@ -6,7 +6,7 @@ QUEUE_NAME = 'f'
logging.basicConfig() logging.basicConfig()
cluster = Cluster([ClusterNode('xx', 'xx', 'xx', 'xx', heartbeat=10)]).start() cluster = Cluster([ClusterNode('192.168.224.31:5672', 'smok', 'smok', 'smok', heartbeat=10)]).start()
a_queue = Queue(QUEUE_NAME, auto_delete=True) a_queue = Queue(QUEUE_NAME, auto_delete=True)
cluster.consume(a_queue) cluster.consume(a_queue)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment