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

feat(contentful): add retry logic to asset downloading #29268

Merged
merged 7 commits into from
Feb 4, 2021

Conversation

axe312ger
Copy link
Collaborator

Contentful users with a huge number of assets might run into issues when requesting to many low quality image previews.

This adds a concurrency of 100 to the download process and a retry logic based on https://github.com/JustinBeckwith/retry-axios.

The very same logic will be applied when detecting the dominant color and creating a traced svg variant, for both gatsby-image and gatsby-plugin-image

@axe312ger axe312ger added status: needs core review Currently awaiting review from Core team member topic: source-contentful Related to Gatsby's integration with Contentful labels Jan 29, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 29, 2021
@axe312ger axe312ger removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 29, 2021
@wardpeet
Copy link
Contributor

wardpeet commented Feb 1, 2021

@axe312gr could you look at https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-filesystem/src/create-remote-file-node.js and move to got instead? Got has everything built in. For mocking I would suggest https://mswjs.io/ which I also used in https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-filesystem/src/__tests__/create-remote-file-node-integration.js.

I'm fine with using nock for now but I would like you to move to got instead. The plan is to move to one fetching library that we can fine tune to make sure it re-uses connections, ...

Nvm, we already using axios

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

Added some comments. I'm curious if it would be possible to have base64 part of contentful sdk? This way we can get the base64 strings in sourceNodes and properly cache things.

Does axios-retry also take care of incomplete downloads? We've seen in source-filesystem that status ok is given but the file did not download all bytes

@axe312ger
Copy link
Collaborator Author

I'm curious if it would be possible to have base64 part of contentful sdk?

No, this is out of scope of our SDK. Ours SDK purpose is to simplify communication with our API, creating base64 variants is not a feature of our API therefore should not be part of the SDK,

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

Let's see if tests pass. Code looks good! Thank you!

@wardpeet wardpeet merged commit 2573224 into master Feb 4, 2021
@wardpeet wardpeet deleted the feat/contentful-add-retry-logic branch February 4, 2021 09:39

let RetryAxios

function getAxios(reporter) {
Copy link
Contributor

@njbmartin njbmartin May 25, 2021

Choose a reason for hiding this comment

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

This slipped past review, reporter never gets passed in from anywhere, so the retry logic never actually works. Test worked due to reporter being stubbed. See #31590

@axe312ger
Copy link
Collaborator Author

@njbmartin yes, you are right :(

const imageResponse = await downloadWithRetry({

@axe312ger
Copy link
Collaborator Author

@njbmartin Thanks again, opened a PR to fix this in the next version: #31608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs core review Currently awaiting review from Core team member topic: source-contentful Related to Gatsby's integration with Contentful
3 participants