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

added flag that tells if connected to broker

parent c3201642
No related branches found
No related tags found
No related merge requests found
......@@ -66,6 +66,8 @@ class Cluster(object):
self.backend = backend
self.node_to_connect_to = itertools.cycle(nodes)
self.connected = False #: public, is connected to broker?
from .handler import ClusterHandlerThread
self.thread = ClusterHandlerThread(self)
......
......@@ -65,6 +65,7 @@ class ClusterHandlerThread(threading.Thread):
except ConnectionFailedError as e:
# a connection failure happened :(
logger.warning('Connecting to %s failed due to %s', node, repr(e))
self.cluster.connected = False
if self.backend is not None:
self.backend.shutdown()
self.backend = None # good policy to release resources before you sleep
......@@ -78,6 +79,7 @@ class ClusterHandlerThread(threading.Thread):
else:
exponential_backoff_delay = 60
else:
self.cluster.connected = True
self.event_queue.put(ConnectionUp())
break # we connected :)
......@@ -140,6 +142,7 @@ class ClusterHandlerThread(threading.Thread):
except ConnectionFailedError as e:
logger.warning('Connection to broker lost')
self.cluster.connected = True
self.event_queue.put(ConnectionDown())
self._reconnect()
......
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