Skip to content

Commit

Permalink
retries: fix issue so max_retries can be overridden to zero via messa…
Browse files Browse the repository at this point in the history
…ge options (#646)
  • Loading branch information
chrisittner authored Aug 22, 2024
1 parent 4c98d9b commit 9ac9b26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dramatiq/middleware/retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def after_process_message(self, broker, message, *, result=None, exception=None)
message.options["traceback"] = traceback.format_exc(limit=30)
message.options["requeue_timestamp"] = int(time.time() * 1000)

max_retries = message.options.get("max_retries") or actor.options.get("max_retries", self.max_retries)
max_retries = message.options.get("max_retries", actor.options.get("max_retries", self.max_retries))
retry_when = actor.options.get("retry_when", self.retry_when)
if retry_when is not None and not retry_when(retries, exception) or \
retry_when is None and max_retries is not None and retries >= max_retries:
Expand Down
7 changes: 4 additions & 3 deletions tests/middleware/test_retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ def do_work():
assert timestamps[-1] - timestamps[0] < 0.2


def test_actors_can_be_assigned_message_max_retries(stub_broker, stub_worker):
@pytest.mark.parametrize("max_retries_message_option", (0, 4))
def test_actors_can_be_assigned_message_max_retries(stub_broker, stub_worker, max_retries_message_option):
# Given that I have a database
attempts = []

Expand All @@ -225,14 +226,14 @@ def do_work():
raise RuntimeError("failure")

# When I send it a message with tight backoff and custom max retries
do_work.send_with_options(max_retries=4, min_backoff=50, max_backoff=500)
do_work.send_with_options(max_retries=max_retries_message_option, min_backoff=50, max_backoff=500)

# And join on the queue
stub_broker.join(do_work.queue_name)
stub_worker.join()

# Then I expect it to be retried as specified in the message options
assert sum(attempts) == 5
assert sum(attempts) == 1 + max_retries_message_option


def test_actors_can_conditionally_retry(stub_broker, stub_worker):
Expand Down

0 comments on commit 9ac9b26

Please sign in to comment.