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

Adding in a function for checking if retries should be performed #294

Merged
merged 4 commits into from Mar 27, 2020
Merged

Adding in a function for checking if retries should be performed #294

merged 4 commits into from Mar 27, 2020

Conversation

smozely
Copy link
Contributor

@smozely smozely commented Mar 27, 2020

Function implemented into the config as per #84

@cherniavskii
Copy link
Contributor

cherniavskii commented Mar 27, 2020

I would love to see function support for "retry" option instead!
That way we'll avoid some edge cases.
What do you think @tannerlinsley @smozely ?
It should not affect compatibility

@smozely
Copy link
Contributor Author

smozely commented Mar 27, 2020

@cherniavskii so you mean replace the current ‘retry’ being allowed to be true or a number ... and allow it to also be a object that covers all the config for retries?

I’d be happy to do that, but just want to make sure @tannerlinsley is ok with going that direction

query.state.failureCount <= query.config.retry
query.config.retryChecker(error, query.state.failureCount) &&
(query.config.retry === true ||
query.state.failureCount <= query.config.retry)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reverse this order so that the checker isn't even called if it's not true or less than the retry count?

@tannerlinsley
Copy link
Collaborator

Yes, I like the idea of just overloading the retry option with the ability to be a function, similar to how retry delays work

@smozely
Copy link
Contributor Author

smozely commented Mar 27, 2020

Yes, I like the idea of just overloading the retry option with the ability to be a function, similar to how retry delays work

Ah right, so for that your saying, if I provide a function for retry, then that function should handle everything ... so I'd end up with something like ...

config.retry: (failureCount, error) => {
  return failureCount <= 5 && error !== 'NoRetry';
}

So I have to implement both the retry count check in my function, and the extra logic ... I'm all cool with that.

@smozely
Copy link
Contributor Author

smozely commented Mar 27, 2020

I've updated with the overloading of the retry config item

@cherniavskii
Copy link
Contributor

So I have to implement both the retry count check in my function, and the extra logic

Yeah, I think it's still way better than dealing with edge cases like:

{
  retry: true,
  retryChecker: () => false,
  // what should happen?
}

query.config.retry === true ||
query.state.failureCount <= query.config.retry
(typeof query.config.retry == 'number' &&
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this check here. If retry is a function, this condition will be falsy

query.state.failureCount <= query.config.retry
(typeof query.config.retry == 'number' &&
query.state.failureCount <= query.config.retry) ||
query.config.retry(query.state.failureCount, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to check if retry is a function before calling it

- Also expand tests to prevent simillar mistake
@smozely
Copy link
Contributor Author

smozely commented Mar 27, 2020

@cherniavskii Thanks for pointing out the mistake with those typeof checks, I also expanded another test which was passing for the wrong reasons with my change

@cherniavskii
Copy link
Contributor

Awesome!

Copy link
Contributor

@cherniavskii cherniavskii left a comment

Choose a reason for hiding this comment

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

LGTM!

@tannerlinsley tannerlinsley merged commit af593d6 into TanStack:master Mar 27, 2020
@smozely
Copy link
Contributor Author

smozely commented Mar 27, 2020

Whoop! thanks folks ... now to replace my home-grown solution with this!

@smozely smozely deleted the retry_checker branch March 27, 2020 23:19
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.

None yet

3 participants