Improve the warning messages that come back when running the master workflow spec.

This commit is contained in:
Dan 2021-10-07 14:43:38 -04:00
parent 548c35a4a3
commit fdce91507c
2 changed files with 20 additions and 7 deletions

View File

@ -430,19 +430,23 @@ class StudyService(object):
def _update_status_of_workflow_meta(workflow_metas, status): def _update_status_of_workflow_meta(workflow_metas, status):
# Update the status on each workflow # Update the status on each workflow
warnings = [] warnings = []
unused_statuses = status.copy() # A list of all the statuses that are not used.
for wfm in workflow_metas: for wfm in workflow_metas:
unused_statuses.pop(wfm.workflow_spec_id, None)
wfm.state_message = '' wfm.state_message = ''
# do we have a status for you # do we have a status for you
if wfm.workflow_spec_id not in status.keys(): if wfm.workflow_spec_id not in status.keys():
warnings.append(ApiError("missing_status", "No status specified for workflow %s" % wfm.workflow_spec_id)) warnings.append(ApiError("missing_status", "No status information provided about workflow %s" % wfm.workflow_spec_id))
continue continue
if not isinstance(status[wfm.workflow_spec_id], dict): if not isinstance(status[wfm.workflow_spec_id], dict):
warnings.append(ApiError(code='invalid_status', warnings.append(ApiError(code='invalid_status',
message=f'Status must be a dictionary with "status" and "message" keys. Name is {wfm.workflow_spec_id}. Status is {status[wfm.workflow_spec_id]}')) message=f'Status must be a dictionary with "status" and "message" keys. Name is {wfm.workflow_spec_id}. Status is {status[wfm.workflow_spec_id]}'))
continue continue
if 'message' in status[wfm.workflow_spec_id].keys():
wfm.state_message = status[wfm.workflow_spec_id]['message']
if 'status' not in status[wfm.workflow_spec_id].keys(): if 'status' not in status[wfm.workflow_spec_id].keys():
warnings.append(ApiError("missing_status", warnings.append(ApiError("missing_status_key",
"Workflow '%s' does not have a status setting" % wfm.workflow_spec_id)) "Workflow '%s' is present in master workflow, but doesn't have a status" % wfm.workflow_spec_id))
continue continue
if not WorkflowState.has_value(status[wfm.workflow_spec_id]['status']): if not WorkflowState.has_value(status[wfm.workflow_spec_id]['status']):
warnings.append(ApiError("invalid_state", warnings.append(ApiError("invalid_state",
@ -450,9 +454,15 @@ class StudyService(object):
wfm.workflow_spec_id, status[wfm.workflow_spec_id]['status'], ",".join(WorkflowState.list()) wfm.workflow_spec_id, status[wfm.workflow_spec_id]['status'], ",".join(WorkflowState.list())
))) )))
continue continue
wfm.state = WorkflowState[status[wfm.workflow_spec_id]['status']] wfm.state = WorkflowState[status[wfm.workflow_spec_id]['status']]
if 'message' in status[wfm.workflow_spec_id].keys():
wfm.state_message = status[wfm.workflow_spec_id]['message'] for status in unused_statuses:
if isinstance(unused_statuses[status], dict) and 'status' in unused_statuses[status]:
warnings.append(ApiError("unmatched_status", "The master workflow provided a status for '%s' a "
"workflow that doesn't seem to exist." %
status))
return warnings return warnings
@staticmethod @staticmethod

View File

@ -41,9 +41,12 @@ class TestStudyStatusMessage(BaseTest):
status = {'bad_name': {'status': 'hidden', 'message': 'This is my status message!'}} status = {'bad_name': {'status': 'hidden', 'message': 'This is my status message!'}}
workflow_metas, warnings = self.run_update_status(status) workflow_metas, warnings = self.run_update_status(status)
self.assertEqual(1, len(warnings)) self.assertEqual(2, len(warnings))
self.assertEqual('missing_status', warnings[0].code) self.assertEqual('missing_status', warnings[0].code)
self.assertEqual('No status specified for workflow random_fact', warnings[0].message) self.assertEqual('No status information provided about workflow random_fact', warnings[0].message)
self.assertEqual('unmatched_status', warnings[1].code)
self.assertEqual('The master workflow provided a status for \'bad_name\' a workflow that doesn\'t'
' seem to exist.', warnings[1].message)
def test_study_status_message_not_dict(self): def test_study_status_message_not_dict(self):
# your entry in the status dictionary is not a dictionary # your entry in the status dictionary is not a dictionary