Skip to content

Commit 6182ecd

Browse files
committed
Text-analytics: retry policy for PUT operations
1 parent bc91a91 commit 6182ecd

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
4+
## v1.0.38 (2020-09-04)
5+
* Text-Analytics API additional functions: `get_analytics` and `get_annotated`
6+
37
## v1.0.36 (2020-05-14)
48
* Text-Analytics API endpoint updated: folders & richer metadata
59
* Extended error handling to support Feed disconnection problems

ravenpackapi/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ravenpackapi.utils.date_formats import as_datetime_str
1616

1717
_VALID_METHODS = ('get', 'post', 'put', 'delete', 'patch')
18-
VERSION = '1.0.37'
18+
VERSION = '1.0.38'
1919

2020
logger = logging.getLogger("ravenpack.core")
2121

ravenpackapi/upload/module.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import logging
12
import mimetypes
23
import os
4+
from time import sleep
35

6+
from ravenpackapi.exceptions import APIException
47
from ravenpackapi.upload.models import (File, FILE_FIELDS,
58
Folder, FOLDER_FIELDS)
69
from ravenpackapi.utils.date_formats import as_datetime_str
710

11+
logger = logging.getLogger("ravenpack.upload")
12+
813

914
class UploadApi(object):
1015
def __init__(self, api):
@@ -90,15 +95,27 @@ def file(self, name_or_file_handler,
9095
file_id = promise['file_id']
9196
location = promise['Location']
9297

93-
self.api.request(
94-
endpoint=location,
95-
method='put',
96-
data=fh,
97-
headers={
98-
"x-amz-server-side-encryption": "AES256",
99-
"Content-Type": content_type,
100-
}
101-
)
98+
attempt = 3
99+
while attempt:
100+
try:
101+
fh.seek(0)
102+
self.api.request(
103+
endpoint=location,
104+
method='put',
105+
data=fh,
106+
headers={
107+
"x-amz-server-side-encryption": "AES256",
108+
"Content-Type": content_type,
109+
}
110+
)
111+
except APIException as e:
112+
attempt -= 1
113+
if attempt == 0:
114+
raise e # raise the exception
115+
logger.warning("Error with PUT file operation - retring")
116+
sleep(1)
117+
else:
118+
break
102119

103120
if close_file: # we opened the handler, so let's close it
104121
fh.close()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '1.0.37'
3+
VERSION = '1.0.38'
44

55
with open('README.rst') as readme_file:
66
readme = readme_file.read()

0 commit comments

Comments
 (0)