docs icon indicating copy to clipboard operation
docs copied to clipboard

Add retry logic to fetch

Open delucis opened this issue 3 years ago • 4 comments

What kind of changes does this PR include?

  • Something else!

Description

Adds retry logic to our githubGet helper to try and mitigate the regular CI failures we get for “Invalid response body” when generating integration pages. Here’s a recent example: https://github.com/withastro/docs/runs/7837529942?check_suite_focus=true#step:4:18

delucis avatar Aug 15 '22 17:08 delucis

Deploy Preview for astro-docs-2 ready!

Name Link
Latest commit 9de5c7f6beef5ec4793d39a1a9ef8a585cc6e9b0
Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/62fb84faa715220008afc273
Deploy Preview https://deploy-preview-1303--astro-docs-2.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Aug 15 '22 17:08 netlify[bot]

Thanks @hippotastic — yeah, this was quick and dirty, sorry! I’ll take a look at that suggestion. I’m also wondering if there’s a nice way to generalise this. We sometimes use fetch directly, other times githubGet.

delucis avatar Aug 15 '22 18:08 delucis

Thanks @hippotastic — yeah, this was quick and dirty, sorry! I’ll take a look at that suggestion. I’m also wondering if there’s a nice way to generalise this. We sometimes use fetch directly, other times githubGet.

No worries at all! The nice thing about p-retry (and most other similar libraries) is that you can simply wrap any function in it and it will support automatic retrying. If you want to bail out (e.g. due to invalid credentials), you just throw new AbortError(...) and it will stop retrying and the error will bubble up.

hippotastic avatar Aug 15 '22 18:08 hippotastic

Ha I retract my approval! @hippotastic's suggestion is much better!

natemoo-re avatar Aug 15 '22 20:08 natemoo-re

I used p-retry now as discussed and tested it locally by simulating a connection error. It's retrying in exponentially increasing intervals for up to 5 times now. PTAL @delucis and @natemoo-re :)

hippotastic avatar Aug 16 '22 11:08 hippotastic

(Please disregard my self-approval. I tried to declare my old review with requested changes as outdated and this was the result. 😆)

hippotastic avatar Aug 16 '22 11:08 hippotastic