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

Add retry option to download from remote url #2577

Conversation

tashirosota
Copy link
Contributor

@tashirosota tashirosota commented Jun 8, 2021

Our project downloads image from imgix by use remote_image_url, but imgix occasionally returns a 503 error and download failed.
So I want to support to retry option in carrierwave.
This option will also be useful for other CDNs or storage.

Source: https://aws.amazon.com/premiumsupport/knowledge-center/s3-resolve-503-slowdown-throttling/?nc1=h_ls

@tashirosota tashirosota force-pushed the add_retry_option_to_download_from_remote_url branch 2 times, most recently from 8184134 to 9551486 Compare June 9, 2021 07:22
@tashirosota tashirosota marked this pull request as ready for review June 9, 2021 07:28
retry
else
raise e
end
Copy link
Member

Choose a reason for hiding this comment

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

Please do not expose a download-specific logic outside of the downloader.
This should be moved to somewhere in CarrierWave::Downloader::Base.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @mshibuya!
Thanks for review, and many thanks for carrierwave!
I fixed for move to CarrierWave::Downloader::Base.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mshibuya
Hi, our application require this option.
Is it possible to merge this PR?

@tashirosota tashirosota force-pushed the add_retry_option_to_download_from_remote_url branch from 9551486 to 62ee7e2 Compare June 13, 2021 09:06
@tashirosota tashirosota requested a review from mshibuya June 13, 2021 09:12
@tashirosota tashirosota force-pushed the add_retry_option_to_download_from_remote_url branch from 62ee7e2 to 2f03617 Compare June 13, 2021 09:19
Copy link
Member

@mshibuya mshibuya left a comment

Choose a reason for hiding this comment

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

Sorry I couldn't follow up, please consider these changes!

# [remote_headers (Hash)] Request headers
#
def download(url, remote_headers = {})
def download(url, download_retry_count = 0, remote_headers = {})
Copy link
Member

Choose a reason for hiding this comment

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

Please don't insert download_retry_count into arguments, this will break existing implementations.

A downloader instance have a reference to an uploader instance, you can just reference uploader.download_retry_count inside the downloader.

rescue CarrierWave::DownloadError
expect(instance.current_download_retry_count).to eq 1
end
end
Copy link
Member

Choose a reason for hiding this comment

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

Testing a certain behavior using its internal state (current_download_retry_count) is not a good idea. Instead, you can use this API to imitate download attempts which fails initially but successes in the next time.
https://github.com/bblimke/webmock#multiple-responses-for-repeated-requests

let(:download_retry_count) { 0 }
it { expect { subject }.to raise_error CarrierWave::DownloadError }

it do
Copy link
Member

Choose a reason for hiding this comment

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

Don't omit the example name (it '...'), unless it can be read naturally using the one-liner syntax.
https://relishapp.com/rspec/rspec-core/docs/subject/one-liner-syntax

@tashirosota tashirosota force-pushed the add_retry_option_to_download_from_remote_url branch 3 times, most recently from c6744ad to aa6a685 Compare August 3, 2021 12:36
@tashirosota
Copy link
Contributor Author

tashirosota commented Aug 3, 2021

@mshibuya
Thanks for review, it became very small this PR.
I fixed it!

@tashirosota tashirosota force-pushed the add_retry_option_to_download_from_remote_url branch from aa6a685 to d15c342 Compare August 3, 2021 12:41
@tashirosota tashirosota requested a review from mshibuya August 3, 2021 12:57
@mshibuya mshibuya merged commit a3ffc53 into carrierwaveuploader:master Aug 3, 2021
@mshibuya
Copy link
Member

mshibuya commented Aug 3, 2021

Awesome, thanks!

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