From 1356591849d1514ff7f2baf8bb21d9c91b2c21c1 Mon Sep 17 00:00:00 2001 From: Cenk Alti Date: Thu, 7 Dec 2023 14:54:42 +0300 Subject: [PATCH] worker uses separate connection from tasks --- kuyruk/worker.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kuyruk/worker.py b/kuyruk/worker.py index a221485..29eef50 100644 --- a/kuyruk/worker.py +++ b/kuyruk/worker.py @@ -131,7 +131,9 @@ def run(self) -> None: logger.debug("End run worker") def _consume_messages(self) -> None: - with self.kuyruk.channel() as ch: + with self.kuyruk.new_connection() as connection: + ch = connection.channel() + # Set prefetch count to 1. If we don't set this, RabbitMQ keeps # sending messages while we are already working on a message. ch.basic_qos(0, 1, False) @@ -140,6 +142,7 @@ def _consume_messages(self) -> None: self._consume_queues(ch) logger.info('Consumer started') self._main_loop(ch) + ch.close() def _main_loop(self, ch: amqp.Channel) -> None: while not self.shutdown_pending.is_set():