also remove tasks based on spiff task diff when terminating a task

This commit is contained in:
jasquat 2023-05-11 09:46:11 -04:00
parent 7ef3e62207
commit 024a99c448
1 changed files with 7 additions and 4 deletions

View File

@ -1778,19 +1778,22 @@ class ProcessInstanceProcessor:
def terminate(self) -> None: def terminate(self) -> None:
start_time = time.time() start_time = time.time()
deleted_tasks = self.bpmn_process_instance.cancel() or [] initial_spiff_tasks = self.bpmn_process_instance.get_tasks()
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( task_service = TaskService(
process_instance=self.process_instance_model, process_instance=self.process_instance_model,
serializer=self._serializer, serializer=self._serializer,
bpmn_definition_to_task_definitions_mappings=self.bpmn_definition_to_task_definitions_mappings, 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. # 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 # 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( tasks_no_longer_in_spiff = TaskModel.query.filter(
and_( and_(
TaskModel.process_instance_id == self.process_instance_model.id, TaskModel.process_instance_id == self.process_instance_model.id,