really need to avoid any kind of caching in the WorkflowSpecService

This commit is contained in:
Dan 2022-02-09 14:43:32 -05:00
parent b2d2491b72
commit 2cc20d4b9d
5 changed files with 12 additions and 13 deletions

View File

@ -105,7 +105,13 @@ def drop_workflow_spec_library(spec_id, library_id):
def validate_workflow_specification(spec_id, study_id=None, test_until=None):
try:
WorkflowService.raise_if_disabled(spec_id, study_id)
master_spec = WorkflowSpecService().master_spec
if study_id is not None:
study_model = session.query(StudyModel).filter(StudyModel.id == study_id).first()
statuses = WorkflowProcessor.run_master_spec(master_spec, study_model)
if spec_id in statuses and statuses[spec_id]['status'] == 'disabled':
raise ApiError(code='disabled_workflow',
message=f"This workflow is disabled. {statuses[spec_id]['message']}")
WorkflowService.test_spec(spec_id, study_id, test_until)
WorkflowService.test_spec(spec_id, study_id, test_until, required_only=True)
except ApiError as ae:

View File

@ -43,6 +43,7 @@ class FileSystemService(object):
else:
category_path = FileSystemService.category_path(spec.category_id)
return category_path
@staticmethod
def workflow_path(spec: WorkflowSpecInfo):
if spec.is_master_spec:

View File

@ -124,16 +124,6 @@ class WorkflowService(object):
workflow_model.study_id,
str(e)))
@staticmethod
def raise_if_disabled(spec_id, study_id):
"""Raise an exception if the workflow is not enabled and can not be executed."""
if study_id is not None:
study_model = session.query(StudyModel).filter(StudyModel.id == study_id).first()
status = StudyService._get_study_status(study_model)
if spec_id in status and status[spec_id]['status'] == 'disabled':
raise ApiError(code='disabled_workflow',
message=f"This workflow is disabled. {status[spec_id]['message']}")
@staticmethod
@timeit
def test_spec(spec_id, validate_study_id=None, test_until=None, required_only=False):

View File

@ -189,7 +189,9 @@ class TestTasksApi(BaseTest):
# Modify the specification, with a major change that alters the flow and can't be deserialized
# effectively, if it uses the latest spec files.
file_path = os.path.join(app.root_path, '..', 'tests', 'data', 'two_forms', 'modified', 'two_forms_struc_mod.bpmn')
self.replace_file(workflow.workflow_spec, "two_forms.bpmn", file_path)
self.workflow_spec_service.scan_file_system()
spec = self.workflow_spec_service.get_spec('two_forms')
self.replace_file(spec, "two_forms.bpmn", file_path)
# This should use the original workflow spec, and just move to the next task
workflow_api_2 = self.get_workflow_api(workflow)

View File

@ -121,7 +121,7 @@ class TestWorkflowSpecValidation(BaseTest):
self.assertEqual(1, len(errors))
self.assertEqual("invalid_field_type", errors[0]['code'])
@patch('crc.services.study_service.StudyService._get_study_status')
@patch('crc.services.workflow_processor.WorkflowProcessor.run_master_spec')
def test_disabled_spec_validation(self, mock_status):
"""A disabled workflow spec should fail validation"""
app.config['PB_ENABLED'] = True