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

feat: Add state-modifying retry policies #2957

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

NikitaZelenskis
Copy link

Add state-modifying retry policies

Description

This PR adds support for state-modifying retry policies by allowing a dictionary mapping of exceptions to state-modifying functions in the RetryPolicy class. This enhancement enables users to modify the workflow state before retry attempts based on specific exceptions.

I think this feature can be very usefull as I am not the only one who needs it. See this discussion

Changes

  • Extended RetryPolicy's retry_on parameter to accept dict[Type[Exception], Callable[[Any, Exception], None]]
  • Updated type hints and documentation
  • Added tutorial section explaining the new functionality

Tests

I have not added a test for this feature as I did not find a a fitting file name for this case and did not want to make my own test file.
If needed I can add a test for this new feature, I would appreciate guidance on the preferred location for adding tests.

All existing tests pass.

@NikitaZelenskis
Copy link
Author

Also as I understand the State/task input can be any type? If that is not the case I would also appreciate some guidance on that

@NikitaZelenskis
Copy link
Author

Hello @nfcampos ,
I completely understand that you must be busy, and I apologize if I'm bothering you. But it has been over 2 weeks ago I submitted the pull request. I was just wondering if there's anything wrong with my pull request or if there's any additional information I can provide to help move it forward. If you have a chance to review it, I'd really appreciate your feedback.

elif isinstance(retry_policy.retry_on, dict):
exception_handler = retry_policy.retry_on.get(type(exc), False)
if callable(exception_handler):
exception_handler(task.input, exc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing else branch here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @nfcampos,
Thank you for your review.
I fixed it and pushed the changes.
I apologize for this oversight.

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

Successfully merging this pull request may close these issues.

2 participants