Commit e8c1dc8a by Jon Yurek

Backoff when we get a SlowDown error

parent dca87ec5
......@@ -329,6 +329,7 @@ module Paperclip
def flush_writes #:nodoc:
@queued_for_write.each do |style, file|
retries = 0
begin
log("saving #{path(style)}")
acl = @s3_permissions[style] || @s3_permissions[:default]
......@@ -357,9 +358,17 @@ module Paperclip
write_options.merge!(@s3_headers)
s3_object(style).write(file, write_options)
rescue AWS::S3::Errors::NoSuchBucket => e
rescue AWS::S3::Errors::NoSuchBucket
create_bucket
retry
rescue AWS::S3::Errors::SlowDown
retries += 1
if retries <= 3
sleep((retries ** 2) * 500)
retry
else
raise
end
ensure
file.rewind
end
......
......@@ -711,6 +711,15 @@ describe Paperclip::Storage::S3 do
"Expect all the files to be deleted."
end
it "will retry to save again but back off on SlowDown" do
@dummy.avatar.stubs(:sleep)
AWS::S3::S3Object.any_instance.stubs(:write).
raises(AWS::S3::Errors::SlowDown.new(stub, stub(status: 503, body: "")))
expect {@dummy.save}.to raise_error(AWS::S3::Errors::SlowDown)
expect(@dummy.avatar).to have_received(:sleep).times(3)
end
context "and saved" do
before do
object = stub
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment