Skip to content

Commit

Permalink
fix: make sure RabbitMQ broker’s enqueue() attempts the correct numbe…
Browse files Browse the repository at this point in the history
…r of preset retries
  • Loading branch information
jenstroeger committed Dec 20, 2024
1 parent 4dd0d71 commit 32a9c71
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dramatiq/brokers/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ def declare_queue(self, queue_name, *, ensure=False):
self._ensure_queue(queue_name)

def _ensure_queue(self, queue_name):
attempts = 1
attempts = 0
while True:
attempts += 1
try:
if queue_name in self.queues_pending:
self._declare_queue(queue_name)
Expand All @@ -262,7 +263,6 @@ def _ensure_queue(self, queue_name):
# caller may initiate new ones of each.
del self.connection

attempts += 1
if attempts > MAX_DECLARE_ATTEMPTS:
raise ConnectionClosed(e) from None

Expand Down Expand Up @@ -321,8 +321,9 @@ def enqueue(self, message, *, delay=None):
},
)

attempts = 1
attempts = 0
while True:
attempts += 1
try:
self.declare_queue(canonical_queue_name, ensure=True)
self.logger.debug("Enqueueing message %r on queue %r.", message.message_id, queue_name)
Expand Down Expand Up @@ -351,7 +352,6 @@ def enqueue(self, message, *, delay=None):
if getattr(e, "reply_code", None) == 404:
self.queues.remove(q_name(queue_name))

attempts += 1
if attempts > MAX_ENQUEUE_ATTEMPTS:
raise ConnectionClosed(e) from None

Expand Down

0 comments on commit 32a9c71

Please sign in to comment.