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

Set retry limit for LastFMImporter #1339

Merged
merged 8 commits into from
Mar 17, 2021
Merged

Set retry limit for LastFMImporter #1339

merged 8 commits into from
Mar 17, 2021

Conversation

amCap1712
Copy link
Member

@amCap1712 amCap1712 commented Mar 13, 2021

The LastFMImporter used to retry indefinitely in case of errors (e.g. 50x). Further, when a page import failed, we used to move to the next page, while the previous pages continued to retry.

We are now restricting the number of retries to 3. We also do not move to the next page while we are still retrying the current page.

A few tests have also been added to ensure that the retry logic works as expected.

Copy link
Collaborator

@shivam-kapila shivam-kapila left a comment

Choose a reason for hiding this comment

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

LGTM overall. No changes required as such. Just a few observations I think can solidify the tests.

Copy link
Collaborator

@alastair alastair left a comment

Choose a reason for hiding this comment

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

Functionality seems sane, though I've not tested it myself.

To confirm the expected functionality:
Before this PR, we just repeatedly retried on http 5xx error. We never retried on 4xx error.
With this change, we now only retry LASTFM_RETRIES times if there is a 5xx page

listenbrainz/webserver/static/js/src/LastFMImporter.tsx Outdated Show resolved Hide resolved
listenbrainz/webserver/static/js/src/LastFMImporter.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

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

The logic looks good, approving for speedy deployment.

One comment about the user-facing side of things, though.

listenbrainz/webserver/static/js/src/LastFMImporter.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

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

I missed a spot!

Unless I'm mistaken, whenever the retry function is called, it should be awaited and we should be returning its content.
For example:
retry(Got ${response.status}); -> return await retry(Got ${response.status});

if (retries <= 0) {
return null;
}
await new Promise((resolve) => setTimeout(resolve, timeout));
Copy link
Collaborator

Choose a reason for hiding this comment

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

just asking a question for my information: will this just pause execution for timeout ms?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct. Sort of an inline setTimeout for the async/await age.

Jest fake timers don't play well with promises and setTimeout so we replace the setTimeout function and don't have to wait for the real timeout.
See jestjs/jest#7151
@MonkeyDo MonkeyDo requested a review from alastair March 16, 2021 16:26
Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

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

Silly to approve myself, but I've done some extra testing and it all seems to work, and the code is a lot neater now, plus extra tests.

MonkeyDo added a commit that referenced this pull request Mar 16, 2021
After merging PR #1339 we will want to reactivate the LastFM Importer that we deactivated with PR #1334
@mayhem mayhem merged commit 987aa9a into master Mar 17, 2021
@mayhem mayhem deleted the lastfm-fix branch March 17, 2021 10:32
mayhem pushed a commit that referenced this pull request Mar 17, 2021
After merging PR #1339 we will want to reactivate the LastFM Importer that we deactivated with PR #1334
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.

5 participants