Skip to content

Commit

Permalink
fix: update submission in s3
Browse files Browse the repository at this point in the history
  • Loading branch information
sujanadh committed Feb 7, 2024
1 parent 3a5d3d1 commit 54ee6b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/backend/app/db/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class DbTaskHistory(Base):
invalidation_history = relationship(
DbTaskInvalidationHistory, lazy="dynamic", cascade="all"
)
actioned_by = relationship(DbUser)
actioned_by = relationship(DbUser, overlaps="task_history_user,user")
task_mapping_issues = relationship(DbTaskMappingIssue, cascade="all")

__table_args__ = (
Expand Down
8 changes: 4 additions & 4 deletions src/backend/app/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import sys
from io import BytesIO
from typing import Any
from typing import Any, Optional

from loguru import logger as log
from minio import Minio
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_file_from_bucket(bucket_name: str, s3_path: str, file_path: str):
client.fget_object(bucket_name, s3_path, file_path)


def get_obj_from_bucket(bucket_name: str, s3_path: str) -> BytesIO:
def get_obj_from_bucket(bucket_name: str, s3_path: str) -> Optional[BytesIO]:
"""Download an S3 object from a bucket and return it as a BytesIO object.
Args:
Expand All @@ -112,8 +112,8 @@ def get_obj_from_bucket(bucket_name: str, s3_path: str) -> BytesIO:
try:
response = client.get_object(bucket_name, s3_path)
return BytesIO(response.read())
except Exception as e:
raise ValueError(str(e)) from e
except Exception:
return None
finally:
if response:
response.close()
Expand Down
19 changes: 11 additions & 8 deletions src/backend/app/submissions/submission_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,17 @@ def update_submission_in_s3(
try:
# Get the last submission date from the metadata
file = get_obj_from_bucket(settings.S3_BUCKET_NAME, metadata_s3_path)
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
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

except Exception as e:
log.warning(str(e))
Expand Down

0 comments on commit 54ee6b1

Please sign in to comment.