Skip to content

Commit

Permalink
for #767 reduce frequency of calls to queueDeclare
Browse files Browse the repository at this point in the history
  • Loading branch information
petersilva committed Nov 10, 2023
1 parent 4459212 commit 48ba11b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions sarracenia/moth/amqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def __init__(self, props, is_subscriber) -> None:

super().__init__(props, is_subscriber)

self.last_qDeclare = time.time()

logging.basicConfig(
format=
'%(asctime)s [%(levelname)s] %(name)s %(funcName)s %(message)s')
Expand Down Expand Up @@ -226,8 +228,13 @@ def _amqp_setup_signal_handler(self, signum, stack):

def metricsReport(self):

if self.is_subscriber and self.connection and self.connection.connected:
self._queueDeclare()
if 'no' in self.o and self.o['no'] < 2 and self.is_subscriber and self.connection and self.connection.connected:
# control frequency of checks for queue size. hardcoded for now.
next_time = self.last_qDeclare + 30
now=time.time()
if next_time <= now:
self._queueDeclare()
self.last_qDeclare=now

super().metricsReport()

Expand Down Expand Up @@ -321,6 +328,11 @@ def getSetup(self) -> None:
logger.critical('could not connect')
break

# only first/lead instance needs to declare a queue and bindings.
if 'no' in self.o and self.o['no'] >= 2:
self.metricsConnect()
return

#logger.info('getSetup connected to {}'.format(self.o['broker'].url.hostname) )

if self.o['prefetch'] != 0:
Expand Down

0 comments on commit 48ba11b

Please sign in to comment.