Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: Retries middleware to set max_retries as an option #517

Open
giuppep opened this issue Dec 8, 2022 · 0 comments
Open

Comments

@giuppep
Copy link
Contributor

giuppep commented Dec 8, 2022

As discussed in #425 it is sometimes useful to do some special handling using the on_failure callback after the last retry. However, at the moment, the on_failure callback does not have any way to dynamically determine if the current retry is the last.

In other words, I think it could be useful to either pass the max_retries information in the message options or add another callback on_last_failure.

Unless I'm missing something, I think the first option should be fairly straightforward to implement by adding a before_enqueue method to the Retries middleware

class Retries(Middleware):
    ...
    def before_enqueue(self, broker, message, delay):
        actor = broker.get_actor(message.actor_name)
        max_retries = message.options.get("max_retries") or actor.options.get(
            "max_retries", self.max_retries
        )
        message.options["max_retries"] = self.max_retries

If you think this could be a useful feature and that the proposed solution makes sense, I'd be happy to open a PR with the change.


As a workaround I'm currently retrieving the actor in the on_failure handler

@dramatiq.actor
def my_callback(message_data, exception_data):
    actor = broker.get_actor(message_data["actor_name"])
    max_retries = actor.options.get("max_retries", 0)

    retries = message_data["options"]["retries"]
    if retries > max_retries:
        print("handling the error")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant