From 854b41378fa6f459c98044c73d8150b8e2248cfe Mon Sep 17 00:00:00 2001 From: jasquat Date: Thu, 30 Mar 2023 16:30:34 -0400 Subject: [PATCH] WIP trying to get resetting to a task within a subprocess working w/ burnettk --- .../services/process_instance_processor.py | 1 + .../services/workflow_execution_service.py | 3 ++ .../integration/test_process_api.py | 1 + .../unit/test_process_instance_processor.py | 32 +++++++++++-------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index 1c32efb8..e572c5ae 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -1348,6 +1348,7 @@ class ProcessInstanceProcessor: for task_to_update in tasks_to_update: # print(f"task_to_update: {task_to_update}") + print(f"task_to_update.state: {task_to_update.state}") TaskService.reset_task_model(task_to_update, state="FUTURE", commit=commit) # TaskService.reset_task_model(task_to_update, state=task_to_update.state, commit=commit) # if task_to_update.task_definition.bpmn_identifier != 'top_level_process_script_after_gate': diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/workflow_execution_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/workflow_execution_service.py index 43927b83..495ab310 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/workflow_execution_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/workflow_execution_service.py @@ -72,6 +72,8 @@ class TaskModelSavingDelegate(EngineStepDelegate): def will_complete_task(self, spiff_task: SpiffTask) -> None: if self._should_update_task_model(): self.current_task_start_in_seconds = time.time() + # import pdb; pdb.set_trace() + spiff_task.task_spec._predict(spiff_task, mask=TaskState.NOT_FINISHED_MASK) if self.secondary_engine_step_delegate: self.secondary_engine_step_delegate.will_complete_task(spiff_task) @@ -108,6 +110,7 @@ class TaskModelSavingDelegate(EngineStepDelegate): # ): # self._update_task_model_with_spiff_task(waiting_spiff_task) if self.last_completed_spiff_task is not None: + import pdb; pdb.set_trace() self.task_service.process_spiff_task_parents(self.last_completed_spiff_task) self.task_service.process_spiff_task_children(self.last_completed_spiff_task) diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py index c5623f47..84d970bd 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py @@ -2618,6 +2618,7 @@ class TestProcessApi(BaseTest): ) assert response.status_code == 200 assert response.json is not None + import pdb; pdb.set_trace() assert response.json["status"] == "complete" response = client.get( diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py index 13a22ced..3d949388 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py @@ -347,30 +347,36 @@ class TestProcessInstanceProcessor(BaseTest): human_task_one = process_instance.active_human_tasks[0] spiff_manual_task = processor.bpmn_process_instance.get_task_from_id(UUID(human_task_one.task_id)) ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one) + human_task_one = process_instance.active_human_tasks[0] + spiff_manual_task = processor.bpmn_process_instance.get_task_from_id(UUID(human_task_one.task_id)) + ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one) + + ### NOTES: + # somehow we are hosing the task state so that when completing tasks of a subprocess, the task AFTER the subprocess task + # is not marked READY but instead stays as FUTURE. Running things like: + # self.last_completed_spiff_task.task_spec._update(self.last_completed_spiff_task) + # and + # self.last_completed_spiff_task.task_spec._predict(self.last_completed_spiff_task, mask=TaskState.NOT_FINISHED_MASK) + # did not help. processor.suspend() - ProcessInstanceProcessor.reset_process(process_instance, str(spiff_manual_task.id), commit=True) + # import pdb; pdb.set_trace() + task_model_to_reset_to = TaskModel.query.join(TaskDefinitionModel).filter(TaskDefinitionModel.bpmn_identifier == 'top_level_subprocess_script').order_by(TaskModel.id.desc()).first() + assert task_model_to_reset_to is not None + ProcessInstanceProcessor.reset_process(process_instance, task_model_to_reset_to.guid, commit=True) + # import pdb; pdb.set_trace() process_instance = ProcessInstanceModel.query.filter_by(id=process_instance.id).first() processor = ProcessInstanceProcessor(process_instance) processor.resume() processor.do_engine_steps(save=True) + import pdb; pdb.set_trace() + assert len(process_instance.active_human_tasks) == 1 human_task_one = process_instance.active_human_tasks[0] spiff_manual_task = processor.bpmn_process_instance.get_task_from_id(UUID(human_task_one.task_id)) ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one) - process_instance = ProcessInstanceModel.query.filter_by(id=process_instance.id).first() - processor = ProcessInstanceProcessor(process_instance) - human_task_one = process_instance.active_human_tasks[0] - spiff_manual_task = processor.bpmn_process_instance.get_task_from_id(UUID(human_task_one.task_id)) - ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one) - human_task_one = process_instance.active_human_tasks[0] - spiff_manual_task = processor.bpmn_process_instance.get_task_from_id(UUID(human_task_one.task_id)) - ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one) - - # recreate variables to ensure all bpmn json was recreated from scratch from the db - process_instance_relookup = ProcessInstanceModel.query.filter_by(id=process_instance.id).first() - assert process_instance_relookup.status == "complete" + assert process_instance.status == "complete" def test_properly_saves_tasks_when_running( self,