Skip to content

Commit

Permalink
HC-213: increase backoff (#16)
Browse files Browse the repository at this point in the history
* increase backoff and utilize random jitter to prevent excessive API calls

* utilize backup method for returning content_length
  • Loading branch information
pymonger authored Jun 2, 2020
1 parent dd3f0d4 commit 443ba6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion osaka/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from __future__ import division
from __future__ import absolute_import

__version__ = "1.0.0"
__version__ = "1.0.1"
__url__ = "https://github.com/hysds/osaka"
__description__ = "Osaka (Object Store Abstraction K Arcitecture)"
16 changes: 13 additions & 3 deletions osaka/storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

standard_library.install_aliases()
import re
import traceback
import backoff
import boto3
import botocore
Expand Down Expand Up @@ -121,7 +122,7 @@ def getSchemes():
return ["s3", "s3s"]

@backoff.on_exception(
backoff.expo, Exception, max_value=3, max_time=13,
backoff.expo, Exception, factor=4, max_time=32, jitter=backoff.random_jitter
)
def reload_obj(self, obj):
"""
Expand Down Expand Up @@ -176,8 +177,17 @@ def put(self, stream, uri):
extra = {"ServerSideEncryption": self.encrypt}
with osaka.storage.file.FileHandlerConversion(stream) as fn:
obj.upload_file(fn, ExtraArgs=extra)
self.reload_obj(obj)
return obj.content_length
try:
self.reload_obj(obj)
return obj.content_length
except:
osaka.utils.LOGGER.warn(
"Exponential backoff on getting content length for {} failed. {}.".format(
uri, traceback.format_exc()
)
)
osaka.utils.LOGGER.warn("Trying alternate method.")
return self.size(uri)

def listAllChildren(self, uri):
"""
Expand Down

0 comments on commit 443ba6a

Please sign in to comment.