Skip to content

Commit

Permalink
Merge pull request #244 from kbase/fix_blank_job_outputs
Browse files Browse the repository at this point in the history
Allow blank method success
  • Loading branch information
Tianhao-Gu authored Jun 2, 2020
2 parents 2930297 + 42ec492 commit 9bb36c1
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions lib/execution_engine2/sdk/EE2Status.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,30 +222,38 @@ def _finish_job_with_error(self, job_id, error_message, error_code, error=None):
)

def _finish_job_with_success(self, job_id, job_output):
"""
Allow either blank job outputs or outputs in a specific format (version/id/result)
:param job_id: The job to finish
:param job_output: Either the job output or {}, else something is not right
"""
output = JobOutput()
output.version = job_output.get("version")
output.id = ObjectId(job_output.get("id"))
output.result = job_output.get("result")
try:
output.validate()
except Exception as e:
self.sdkmr.logger.debug(e)
error_message = "Something was wrong with the output object"
error_code = ErrorCode.job_missing_output.value
error = {
"code": -1,
"name": "Output object is invalid",
"message": str(e),
"error": str(e),
}

self.sdkmr.get_mongo_util().finish_job_with_error(
job_id=job_id,
error_message=error_message,
error_code=error_code,
error=error,
)
raise Exception(str(e) + str(error_message))
if job_output != {}:
try:
output.validate()
except Exception as e:
self.sdkmr.logger.debug(e)
error_message = "Something was wrong with the output object"
error_code = ErrorCode.job_missing_output.value
error = {
"code": -1,
"name": "Output object is invalid",
"message": str(e),
"error": str(e),
}

self.sdkmr.get_mongo_util().finish_job_with_error(
job_id=job_id,
error_message=error_message,
error_code=error_code,
error=error,
)
raise Exception(str(e) + str(error_message))

self.sdkmr.get_mongo_util().finish_job_with_success(
job_id=job_id, job_output=job_output
Expand Down

0 comments on commit 9bb36c1

Please sign in to comment.