From 764237d1024c5dbfb6bfa5c415f1bfec92efec2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Sat, 28 May 2016 14:36:21 +0200 Subject: [PATCH] added flag that tells if connected to broker --- coolamqp/cluster.py | 2 ++ coolamqp/handler.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/coolamqp/cluster.py b/coolamqp/cluster.py index 8ac7270..bd85db9 100644 --- a/coolamqp/cluster.py +++ b/coolamqp/cluster.py @@ -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) diff --git a/coolamqp/handler.py b/coolamqp/handler.py index c74581b..b6cb3c7 100644 --- a/coolamqp/handler.py +++ b/coolamqp/handler.py @@ -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() -- GitLab