Commit 86e08a97 authored by Vladir Parrado Cruz's avatar Vladir Parrado Cruz

More retrying cases for the APIs requests.

parent a72aebf4
......@@ -129,22 +129,30 @@ def check_status(
retry_count = 0
while processing:
response = requests.post(
url,
headers={
'Authorization': 'Token {} Domain {}'.format(
TOKEN,
DOMAIN
)
},
files={
'meta': (
'meta',
json.dumps(json_contents).encode('utf-8'),
'application/json'
try:
response = requests.post(
url,
headers={
'Authorization': 'Token {} Domain {}'.format(
TOKEN,
DOMAIN
)
},
files={
'meta': (
'meta',
json.dumps(json_contents).encode('utf-8'),
'application/json'
)
}
)
except Exception as e:
print(
'Got error while checking the status: {}. Retrying...'.format(
str(e)
)
}
)
)
continue
status_code = response.status_code
......@@ -211,13 +219,21 @@ def main():
print("POSTING to ", url)
sent = False
while not sent:
sent, msg = send_request(
url,
image_file_hash,
relative_path,
original_image_size,
img_bytes
)
try:
sent, msg = send_request(
url,
image_file_hash,
relative_path,
original_image_size,
img_bytes
)
except requests.exceptions.ConnectionError:
print(
'The API seems to be in trouble, or there '
'is a deployment in progress retrying...'
)
time.sleep(10)
continue
time.sleep(5)
if sent:
time.sleep(10)
......
......@@ -201,23 +201,30 @@ def check_status(
processing = True
retry_count = 0
while processing:
response = requests.post(
url,
headers={
'Authorization': 'Token {} Domain {}'.format(
TOKEN,
DOMAIN
)
},
files={
'meta': (
'meta',
json.dumps(json_contents).encode('utf-8'),
'application/json'
try:
response = requests.post(
url,
headers={
'Authorization': 'Token {} Domain {}'.format(
TOKEN,
DOMAIN
)
},
files={
'meta': (
'meta',
json.dumps(json_contents).encode('utf-8'),
'application/json'
)
}
)
except Exception as e:
print(
'Got error while checking the status: {}. Retrying...'.format(
str(e)
)
}
)
)
continue
status_code = response.status_code
if status_code == 200:
......
......@@ -25,7 +25,7 @@ WIDTH_LIST = [
b'90',
]
DOMAIN = "original.vteximg.com.br"
TOKEN = ""
TOKEN = "613a35d99f655b4197afa3167610ed4d93adda1a"
# One of these https://gitlab.zunzun.se/public-items/imgopt3-api-docs/blob/develop/lux/lux_api_2020_4.yaml#L281
PRECURSOR_NAME = 'avifo0'
QUALITY_LIST = [
......@@ -211,22 +211,30 @@ def check_status(
processing = True
retry_count = 0
while processing:
response = requests.post(
url,
headers={
'Authorization': 'Token {} Domain {}'.format(
TOKEN,
DOMAIN
)
},
files={
'meta': (
'meta',
json.dumps(json_contents).encode('utf-8'),
'application/json'
try:
response = requests.post(
url,
headers={
'Authorization': 'Token {} Domain {}'.format(
TOKEN,
DOMAIN
)
},
files={
'meta': (
'meta',
json.dumps(json_contents).encode('utf-8'),
'application/json'
)
}
)
except Exception as e:
print(
'Got error while checking the status: {}. Retrying...'.format(
str(e)
)
}
)
)
continue
status_code = response.status_code
if status_code == 200:
......
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