Pull request #36: RED-4049 fix: Pyinfra now retries to reconnect after AMPQ connection loss and eventually throws an error if unsuccessful, forcing container restart.

Merge in RR/pyinfra from RED-4049-AMQP-reconnect to master

Squashed commit of the following:

commit 1baafb781c9f623faf4223043e1185fd4ecbbe0e
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Tue May 17 14:36:47 2022 +0200

    RED-4049 fix: Pyinfra now retries to reconnect after AMPQ connection loss and eventually throws an error if unsuccessful, forcing container restart.
This commit is contained in:
Julius Unverfehrt 2022-05-17 14:41:03 +02:00
parent d95b483917
commit 4f18dbc60d

View File

@ -51,12 +51,11 @@ def main():
response_strategy = StorageStrategy(storage)
visitor = QueueVisitor(storage, callback, response_strategy)
queue_manager = PikaQueueManager(CONFIG.rabbitmq.queues.input, CONFIG.rabbitmq.queues.output)
@retry(ConsumerError, tries=3, delay=5, jitter=(1, 3))
def consume():
consumer = Consumer(visitor, queue_manager)
try:
try: # RED-4049 queue manager needs to be in try scope to eventually throw Exception after connection loss.
queue_manager = PikaQueueManager(CONFIG.rabbitmq.queues.input, CONFIG.rabbitmq.queues.output)
consumer = Consumer(visitor, queue_manager)
consumer.basic_consume_and_publish()
except Exception as err:
raise ConsumerError from err