From ff6a770a1087b9696d79e231ae0ef756ce39dee8 Mon Sep 17 00:00:00 2001 From: Reid Sunderland Date: Fri, 9 Aug 2024 20:47:38 +0000 Subject: [PATCH] Fix #953 by only connecting when necessary, re-enable passive queue declare to get number of messages in queue --- sarracenia/moth/amqp.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sarracenia/moth/amqp.py b/sarracenia/moth/amqp.py index 2c9429a67..e05d3953c 100755 --- a/sarracenia/moth/amqp.py +++ b/sarracenia/moth/amqp.py @@ -242,7 +242,7 @@ def metricsReport(self): next_time = self.last_qDeclare + 30 now=time.time() if next_time <= now: - #self._queueDeclare(passive=True) + self._queueDeclare(passive=True) self.last_qDeclare=now super().metricsReport() @@ -253,11 +253,12 @@ def _queueDeclare(self,passive=False) -> int: try: # from sr_consumer.build_connection... - if not self.__connect(self.o['broker']): - logger.critical('could not connect') - if hasattr(self,'metrics'): - self.metrics['brokerQueuedMessageCount'] = -2 - return -2 + if not self.connection or not self.connection.connected: + if not self.__connect(self.o['broker']): + logger.critical('could not connect') + if hasattr(self,'metrics'): + self.metrics['brokerQueuedMessageCount'] = -2 + return -2 #FIXME: test self.first_setup and props['reset']... delete queue... broker_str = self.o['broker'].url.geturl().replace(