Skip to content

Commit

Permalink
Fix: error handling in s3
Browse files Browse the repository at this point in the history
  • Loading branch information
sujanadh committed Feb 8, 2024
1 parent 54ee6b1 commit 68aea77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/backend/app/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ def get_obj_from_bucket(bucket_name: str, s3_path: str) -> Optional[BytesIO]:
try:
response = client.get_object(bucket_name, s3_path)
return BytesIO(response.read())
except Exception:
return None
except Exception as e:
log.warning(f"Failed attempted download from S3 path: {s3_path}")
raise ValueError(str(e)) from e
finally:
if response:
response.close()
Expand Down
23 changes: 10 additions & 13 deletions src/backend/app/submissions/submission_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,19 @@ def update_submission_in_s3(
metadata_s3_path = f"/{s3_project_path}/submissions.meta.json"
try:
# Get the last submission date from the metadata
file = get_obj_from_bucket(settings.S3_BUCKET_NAME, metadata_s3_path)
if file:
zip_file_last_submission = (json.loads(file.getvalue()))[
"last_submission"
]
if last_submission <= zip_file_last_submission:
# Update background task status to COMPLETED
update_bg_task_sync = async_to_sync(
project_crud.update_background_task_status_in_database
)
update_bg_task_sync(db, background_task_id, 4) # 4 is COMPLETED
return
data = get_obj_from_bucket(settings.S3_BUCKET_NAME, metadata_s3_path)

zip_file_last_submission = (json.loads(data.getvalue()))["last_submission"]
if last_submission <= zip_file_last_submission:
# Update background task status to COMPLETED
update_bg_task_sync = async_to_sync(
project_crud.update_background_task_status_in_database
)
update_bg_task_sync(db, background_task_id, 4) # 4 is COMPLETED
return

except Exception as e:
log.warning(str(e))
pass

# Zip file is outdated, regenerate
metadata = {
Expand Down

0 comments on commit 68aea77

Please sign in to comment.