From 57fcadbd6272d351c7c30fbcd4f6b303372881f6 Mon Sep 17 00:00:00 2001 From: jasquat Date: Wed, 10 May 2023 12:02:48 -0400 Subject: [PATCH] save all spiff tasks to the db after terminating a process instance w/ burnettk --- .../services/process_instance_processor.py | 13 +++++++++++-- .../integration/test_process_api.py | 5 +++++ 2 files changed, 16 insertions(+), 2 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 f806eb481..9ac3c432f 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -1891,8 +1891,17 @@ class ProcessInstanceProcessor: return None def terminate(self) -> None: - """Terminate.""" - self.bpmn_process_instance.cancel() + start_time = time.time() + deleted_tasks = self.bpmn_process_instance.cancel() or [] + spiff_tasks = self.bpmn_process_instance.get_tasks() + + task_service = TaskService( + process_instance=self.process_instance_model, + serializer=self._serializer, + bpmn_definition_to_task_definitions_mappings=self.bpmn_definition_to_task_definitions_mappings, + ) + task_service.update_all_tasks_from_spiff_tasks(spiff_tasks, deleted_tasks, start_time) + self.save() self.process_instance_model.status = "terminated" db.session.add(self.process_instance_model) 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 0e731a245..0e59fdd89 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py @@ -1607,6 +1607,10 @@ class TestProcessApi(BaseTest): assert response.status_code == 200 assert response.json is not None + ready_tasks = TaskModel.query.filter_by(process_instance_id=process_instance_id, state="READY").all() + assert len(ready_tasks) == 1 + ready_task = ready_tasks[0] + response = client.post( f"/v1.0/process-instance-terminate/{self.modify_process_identifier_for_path_param(process_model_identifier)}/{process_instance_id}", headers=self.logged_in_headers(with_super_admin_user), @@ -1617,6 +1621,7 @@ class TestProcessApi(BaseTest): process_instance = ProcessInstanceModel.query.filter_by(id=process_instance_id).first() assert process_instance assert process_instance.status == "terminated" + assert ready_task.state == "CANCELLED" def test_process_instance_delete( self,