Skip to content

Commit

Permalink
Handle submission upload failure to SQS message queues(#328)
Browse files Browse the repository at this point in the history
* Raise submission upload failure error after publishing submission message

* Publish submission message on failure

* Publish submission message on failure

* Fix unused import
  • Loading branch information
Ram81 committed Jun 8, 2021
1 parent 1086eb5 commit b47f700
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions evalai/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def upload_file_to_s3(file, presigned_urls, max_chunk_size):
}
except Exception as err:
echo(style("\nThere was an error while uploading the file: {}".format(err), fg="red", bold=True))
sys.exit(1)
response = {
"success": False,
"parts": []
}
return response


Expand Down Expand Up @@ -149,6 +152,16 @@ def generate_random_string(length):
return "".join(random.choice(letter_set) for _ in range(length))


def publish_submission_message(challenge_phase_pk, submission_pk, headers):
url = "{}{}".format(get_host_url(), URLS.send_submission_message.value)
url = url.format(challenge_phase_pk, submission_pk)
response = requests.post(
url,
headers=headers,
)
return response


def upload_file_using_presigned_url(challenge_phase_pk, file, file_type, submission_metadata={}):
if file_type == "submission":
url = "{}{}".format(get_host_url(), URLS.get_presigned_url_for_submission_file.value)
Expand Down Expand Up @@ -199,28 +212,29 @@ def upload_file_using_presigned_url(challenge_phase_pk, file, file_type, submiss
# Uploading the file to S3
response = upload_file_to_s3(file, presigned_urls, max_chunk_size)

if not response["success"] and file_type == "submission":
# Publishing submission message to the message queue for processing
response = publish_submission_message(challenge_phase_pk, submission_pk, headers)
response.raise_for_status()

data = {
"parts": json.dumps(response.get("parts")),
"upload_id": upload_id
}

# Complete multipart S3 upload
response = requests.post(
upload_response = requests.post(
finish_upload_url, headers=headers, data=data
)

if response.status_code is not HTTPStatus.OK:
response.raise_for_status()

if file_type == "submission":
# Publishing submission message to the message queue for processing
url = "{}{}".format(get_host_url(), URLS.send_submission_message.value)
url = url.format(challenge_phase_pk, submission_pk)
response = requests.post(
url,
headers=headers,
)
response = publish_submission_message(challenge_phase_pk, submission_pk, headers)
response.raise_for_status()

# Publish submission before throwing submission upload error
if upload_response.status_code is not HTTPStatus.OK:
upload_response.raise_for_status()
except requests.exceptions.HTTPError as err:
if response.status_code in EVALAI_ERROR_CODES:
validate_token(response.json())
Expand Down

0 comments on commit b47f700

Please sign in to comment.