From 024a99c448200d1c82a58669f4ac17f4555a6e27 Mon Sep 17 00:00:00 2001 From: jasquat Date: Thu, 11 May 2023 09:46:11 -0400 Subject: [PATCH] also remove tasks based on spiff task diff when terminating a task --- .../services/process_instance_processor.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 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 657965db7..aa25020c3 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -1778,19 +1778,22 @@ class ProcessInstanceProcessor: def terminate(self) -> None: start_time = time.time() - deleted_tasks = self.bpmn_process_instance.cancel() or [] - spiff_tasks = self.bpmn_process_instance.get_tasks() + initial_spiff_tasks = self.bpmn_process_instance.get_tasks() + + self.bpmn_process_instance.cancel() + current_spiff_tasks = self.bpmn_process_instance.get_tasks() + deleted_spiff_tasks = [t for t in initial_spiff_tasks if t not in current_spiff_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) + task_service.update_all_tasks_from_spiff_tasks(current_spiff_tasks, deleted_spiff_tasks, start_time) # we may want to move this to task_service.update_all_tasks_from_spiff_tasks but not sure it's always good to it. # for cancelled tasks, spiff only returns tasks that were cancelled, not the ones that were deleted so we have to find them - spiff_task_guids = [str(st.id) for st in spiff_tasks] + spiff_task_guids = [str(st.id) for st in current_spiff_tasks] tasks_no_longer_in_spiff = TaskModel.query.filter( and_( TaskModel.process_instance_id == self.process_instance_model.id,