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

[Question] Cancel a retry policy #25

Closed
conradob opened this issue Jul 7, 2020 · 5 comments
Closed

[Question] Cancel a retry policy #25

conradob opened this issue Jul 7, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@conradob
Copy link

conradob commented Jul 7, 2020

Sorry to raise an issue just to ask a question but is there a way to cancel a retry policy?

The use case I'm trying to achieve is if the user attempts to redo the same action that was being retried, would like to cancel the current retry and then create a new retry with the updated data.

Is it possible?

Thanks for the terrific work with this tool.

@connor4312
Copy link
Owner

Not right now. Something I've been meaning to do has been allowing you to pass a cancellation token through IPolicy.execute. I'll add that tonight.

@connor4312 connor4312 added the enhancement New feature or request label Jul 7, 2020
@connor4312 connor4312 self-assigned this Jul 7, 2020
@connor4312
Copy link
Owner

Added: https://github.com/connor4312/cockatiel#retryexecutefn-cancellationtoken

Cancelling the token will cause the last error emitted by the function to be bubbled.

@conradob
Copy link
Author

conradob commented Jul 9, 2020

I'm not sure if I'm missing something but I couldn't make the retry policy stop using the cancellation token.

Here follow the example of a simple experiment I did to cancel a retry after 5 attempts.

I know cockatiel provide retry policy attempts but this is just a figurative test to play with the cancellation token

https://github.com/conradob/cockatiel-retry-playground

@connor4312
Copy link
Owner

You need to pass in the cancellation token, not the source:

diff --git a/index.js b/index.js
index ad8a922..32d3c1e 100644
--- a/index.js
+++ b/index.js
@@ -25,7 +25,7 @@ const main = async () => {
 
   const result = await retryPolicy.execute(
     () => failCallback(),
-    cancellationTokenSource
+    cancellationTokenSource.token
   )

   console.log(result)

@conradob
Copy link
Author

conradob commented Jul 9, 2020

That is it.
Perfect. Thanks for all your support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants