Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Add a way for actors to access the current message #208
Can you use
def should_retry(retries_so_far, e): ... @actor(retry_when=should_retry) def some_fn(): ...
Otherwise, you can define a middleware that exposes the current message using a thread-local variable:
class CurrentMessage(Middleware): STATE = local() @classmethod def get_current_message(): return getattr(CurrentMessage.STATE, "message", None) def before_process_message(self, broker, message): setattr(self.STATE, "message", message) def after_process_message(self, broker, message, *, result=None, exception=None): delattr(self.STATE, "message")
I'll probably add something like this to one of the upcoming versions since having access to the current message can sometimes be useful.