better abstraction and error handling/logging

This commit is contained in:
brmnjsh
2023-09-15 19:34:31 +00:00
parent 00ba6f4fc3
commit 64a1011604
4 changed files with 31 additions and 9 deletions

View File

@ -11,12 +11,21 @@ class AbilityEstimationService(Base):
def process(self):
attributes = self.service_attributes()
ability_estimation = AbilityEstimation.parse_obj(attributes)
# we need to convert the results from numpy array to a list to dump to json
json_data = json.dumps(ability_estimation.calculate().tolist())
result = ability_estimation.calculate()
# temp file name
self.file_name = f'{ability_estimation.exam_id}_ability_estimation_result.json'
if result is not None:
response = json.dumps({
'status': 'success',
'result': result
})
self.file_name = f'{ability_estimation.exam_id}_ability_estimation_result.json'
else:
response = json.dumps({
'status': 'error',
'result': None
})
return aws_helper.file_stream_upload(
io.BytesIO(bytes(json_data.encode('UTF-8'))), self.file_name,
io.BytesIO(bytes(response.encode('UTF-8'))), self.file_name,
ApplicationConfigs.s3_processed_bucket, self.ACTION)