Skip to content

Commit 3823d82

Browse files
committed
SCP-8 added sentry and updated backoff on photo upload to bucket
1 parent 3b0c0cd commit 3823d82

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

skylab_studio/studio_client.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import base64
1515
import hashlib
1616
import requests
17-
from io import BytesIO
17+
# from io import BytesIO
18+
import sentry_sdk
1819

1920
from .version import VERSION
2021
from .studio_exception import StudioException
@@ -62,7 +63,7 @@ def __init__(self, api_key=None, **kwargs):
6263

6364
if 'debug' in kwargs:
6465
self.debug = kwargs['debug']
65-
66+
6667
if 'max_concurrent_downloads' in kwargs:
6768
self.max_concurrent_downloads = kwargs['max_concurrent_downloads']
6869

@@ -72,6 +73,18 @@ def __init__(self, api_key=None, **kwargs):
7273
LOGGER.debug('Debug enabled')
7374
LOGGER.propagate = True
7475

76+
# initialize sentry
77+
sentry_sdk.init(
78+
dsn="https://[email protected]/4507850876452864",
79+
# Set traces_sample_rate to 1.0 to capture 100%
80+
# of transactions for tracing.
81+
traces_sample_rate=1.0,
82+
# Set profiles_sample_rate to 1.0 to profile 100%
83+
# of sampled transactions.
84+
# We recommend adjusting this value in production.
85+
profiles_sample_rate=1.0,
86+
)
87+
7588
def _build_http_auth(self):
7689
return (self.api_key, '')
7790

@@ -331,6 +344,8 @@ def _upload_photo(self, photo_path, id, model='job'):
331344

332345
try:
333346
upload_photo_resp = requests.put(upload_url, data, headers=headers)
347+
# Will raise exception for any statuses 4xx-5xx
348+
upload_photo_resp.raise_for_status()
334349

335350
if not upload_photo_resp:
336351
print('First upload attempt failed, retrying...')
@@ -347,9 +362,15 @@ def _upload_photo(self, photo_path, id, model='job'):
347362
time.sleep(1) # Wait for a moment before retrying
348363
retry += 1
349364

365+
except requests.exceptions.HTTPError as e:
366+
sentry_sdk.capture_exception(e)
367+
print("HTTP error occurred while trying to upload your photo:", e)
368+
350369
except Exception as e:
370+
sentry_sdk.capture_exception(e)
351371
print(f"An exception of type {type(e).__name__} occurred: {e}")
352372
print('Deleting created, but unuploaded photo...')
373+
353374
self.delete_photo(photo_id)
354375

355376
res['upload_response'] = upload_photo_resp.status_code

0 commit comments

Comments
 (0)