-
Notifications
You must be signed in to change notification settings - Fork 3k
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(retry): Add configurable delay #6421
Conversation
src/internal/operators/retry.ts
Outdated
* A more configurable means of retrying a source. | ||
* | ||
* If `delay` is provided as a `number`, after the source errors, the result will wait `delay` milliseconds, | ||
* then retry the source. If `delay` is a function, th |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this sentence is not finished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so weird. I feel like this is the third or fourth time this has happened to me, but only with doc comments :\
isnt // like `retry`
retryWhen(count(n));
retryWhen(count({ count: n, resetOnSuccess: true }));
// exponential backoff
retryWhen(exponentialBackoff({ startDelay: d, maxDelay: m }));
// custom, like current `retryWhen`
retryWhen(createMyCustomNotifier); |
I somewhat agree with this, but AFAICT the following would not be possible with retryWhen(count({ count: n, resetOnSuccess: true })); I'm more curious as to whether this PR hints at a general approach for reducing the number of core operators by making them more 'configurable' - as was done with |
i think the current state of
funnily enough that hinted me into finding a bug in the custom retry backoff operator that I use and caused various services to restart without "retrying enough" - because the attempt counter was not reset. but I noticed immediately the follow up question: what is success? or when should the attempt counter actually be reset? |
Notes from core team: General approval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, but I'm not sure about the resetOnSuccess
name:
/**
* Whether or not to reset the retry counter on success.
* Defaults to false.
*/
resetOnSuccess?: boolean;
What is success? The accompanying doc/comment doesn't make this clear. The other reset
options in the API are, IMO, a little clearer: resetOnError
, resetOnComplete
, resetOnDisconnect
, resetOnRefCountZero
.
I mean, from resetOnSuccess
a caller could infer that it could only mean that it'll reset when a next
notification is received - because resetting on complete would be meaningless - but should the caller really need to even think about this?
Maybe resetOnNext
?
- Adds a `delay` configuration that allows the user to create simpler exponential backoff, simple retry delays, and/or other functionality.
e53c338
to
32ab5e2
Compare
@cartant I've changed the one setting to |
@cartant Just realized that |
delay
configuration that allows the user to create simpler exponential backoff, simple retry delays, and/or other functionality.Basically, this will allow a user to write an exponential backoff or simple delay more easily and intuitively than
retryWhen
could. In fact, we might want to deprecateretryWhen
in favor of this, and also add this pattern torepeat
(if we decide it's a good idea).Retry every 5 seconds, a maximum of 100 times:
Exponential backoff example:
Notes
Honestly, I'm okay even with adding configuration for the above backoff scenario, given it's such a common thing I've had to implement. Even if all we did was provide a helper function that was easy to tree shake like:
retry({ delay: exponentialBackoff({ startDelay: 1000, maxDelay: 60000 }) })
or the like.