When a study is put on hold, we now reset workflows and call any pending cancel_notify events.
In api.study.update_study we test the study status and call the new WorkflowService method process_workflows_for_cancels. In services.workflow_service we added the new method process_workflows_for_cancels. It loops through workflows for a study, and resets them if they are in progress. In services.workflow_processor, we changed the reset method to be an instance method so we can call self.cancel_notify. In tests.test_lookup_service we changed the call to WorkflowProcessor.reset to reflect the change from class method to instance method
This commit is contained in:
parent
cccb722e07
commit
7e76639cf3
|
@ -9,6 +9,7 @@ from crc.models.protocol_builder import ProtocolBuilderStatus
|
||||||
from crc.models.study import Study, StudyEvent, StudyEventType, StudyModel, StudySchema, StudyForUpdateSchema, StudyStatus
|
from crc.models.study import Study, StudyEvent, StudyEventType, StudyModel, StudySchema, StudyForUpdateSchema, StudyStatus
|
||||||
from crc.services.study_service import StudyService
|
from crc.services.study_service import StudyService
|
||||||
from crc.services.user_service import UserService
|
from crc.services.user_service import UserService
|
||||||
|
from crc.services.workflow_service import WorkflowService
|
||||||
|
|
||||||
|
|
||||||
def add_study(body):
|
def add_study(body):
|
||||||
|
@ -63,6 +64,10 @@ def update_study(study_id, body):
|
||||||
|
|
||||||
session.add(study_model)
|
session.add(study_model)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
if status == StudyStatus.abandoned or status == StudyStatus.hold:
|
||||||
|
WorkflowService.process_workflows_for_cancels(study_id)
|
||||||
|
|
||||||
# Need to reload the full study to return it to the frontend
|
# Need to reload the full study to return it to the frontend
|
||||||
study = StudyService.get_study(study_id)
|
study = StudyService.get_study(study_id)
|
||||||
return StudySchema().dump(study)
|
return StudySchema().dump(study)
|
||||||
|
|
|
@ -196,10 +196,10 @@ class WorkflowProcessor(object):
|
||||||
else:
|
else:
|
||||||
self.is_latest_spec = False
|
self.is_latest_spec = False
|
||||||
|
|
||||||
@classmethod
|
def reset(self, workflow_model, clear_data=False):
|
||||||
def reset(cls, workflow_model, clear_data=False):
|
|
||||||
print('WorkflowProcessor: reset: ')
|
print('WorkflowProcessor: reset: ')
|
||||||
|
|
||||||
|
self.cancel_notify()
|
||||||
workflow_model.bpmn_workflow_json = None
|
workflow_model.bpmn_workflow_json = None
|
||||||
if clear_data:
|
if clear_data:
|
||||||
# Clear form_data from task_events
|
# Clear form_data from task_events
|
||||||
|
@ -209,7 +209,7 @@ class WorkflowProcessor(object):
|
||||||
task_event.form_data = {}
|
task_event.form_data = {}
|
||||||
session.add(task_event)
|
session.add(task_event)
|
||||||
session.commit()
|
session.commit()
|
||||||
return cls(workflow_model)
|
return self.__init__(workflow_model)
|
||||||
|
|
||||||
def __get_bpmn_workflow(self, workflow_model: WorkflowModel, spec: WorkflowSpec, validate_only=False):
|
def __get_bpmn_workflow(self, workflow_model: WorkflowModel, spec: WorkflowSpec, validate_only=False):
|
||||||
if workflow_model.bpmn_workflow_json:
|
if workflow_model.bpmn_workflow_json:
|
||||||
|
|
|
@ -704,5 +704,10 @@ class WorkflowService(object):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def process_workflows_for_cancels(study_id):
|
||||||
|
workflows = db.session.query(WorkflowModel).filter_by(study_id=study_id).all()
|
||||||
|
for workflow in workflows:
|
||||||
|
if workflow.status == WorkflowStatus.user_input_required or workflow.status == WorkflowStatus.waiting:
|
||||||
|
processor = WorkflowProcessor(workflow)
|
||||||
|
processor.reset(workflow)
|
||||||
|
|
|
@ -54,7 +54,8 @@ class TestLookupService(BaseTest):
|
||||||
|
|
||||||
# restart the workflow, so it can pick up the changes.
|
# restart the workflow, so it can pick up the changes.
|
||||||
|
|
||||||
processor = WorkflowProcessor.reset(workflow)
|
processor = WorkflowProcessor(workflow)
|
||||||
|
processor.reset(workflow)
|
||||||
workflow = processor.workflow_model
|
workflow = processor.workflow_model
|
||||||
|
|
||||||
LookupService.lookup(workflow, "sponsor", "sam", limit=10)
|
LookupService.lookup(workflow, "sponsor", "sam", limit=10)
|
||||||
|
|
Loading…
Reference in New Issue