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

fix: Add simple retries on network errors #113

Merged
merged 1 commit into from
Mar 15, 2023

Conversation

adinhodovic
Copy link
Contributor

No description provided.

Copy link
Owner

@czue czue left a comment

Choose a reason for hiding this comment

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

thanks! one (maybe dumb) question about how this works...

error = networkError;
this.onNetworkError(this.progressBarElement, this.progressBarMessageElement, "Network Error");
attempts++;
await new Promise(r => setTimeout(r, 1000));
Copy link
Owner

Choose a reason for hiding this comment

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

sorry my async JS is not so good. How does this end up doing a retry? like how does it know what to call again?

Copy link
Contributor Author

@adinhodovic adinhodovic Mar 15, 2023

Choose a reason for hiding this comment

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

My JS in general isnt great :D.

But it's just a while loop that try and catches in til the maxnetworkRetryAttempts are hit or if a request is successful.

while(!success && attempts < this.maxNetworkRetryAttempts) {

then runs the try { catches the error and goes again

Copy link
Owner

Choose a reason for hiding this comment

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

Ah right, duh. And this is essentially the equivalent of an async sleep?

Edit: Looks like yes https://stackoverflow.com/a/39914235/8207

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, this was just not to spam the backend with requests every miliseconds or so.

error = networkError;
this.onNetworkError(this.progressBarElement, this.progressBarMessageElement, "Network Error");
attempts++;
await new Promise(r => setTimeout(r, 1000));
Copy link
Owner

Choose a reason for hiding this comment

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

Ah right, duh. And this is essentially the equivalent of an async sleep?

Edit: Looks like yes https://stackoverflow.com/a/39914235/8207

@czue czue merged commit b495ff8 into czue:master Mar 15, 2023
@adinhodovic
Copy link
Contributor Author

@czue could we bump and release a new version to pypi? Thanks!

@czue
Copy link
Owner

czue commented Apr 3, 2023

Done! Sorry about the delay. https://github.com/czue/celery-progress/releases/tag/0.3

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