Skip to content

Commit

Permalink
worker uses separate connection from tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Dec 7, 2023
1 parent 33e3efe commit 1356591
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kuyruk/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
Expand Down

0 comments on commit 1356591

Please sign in to comment.