only delete active tasks if needed w/ burnettk cullerton

This commit is contained in:
jasquat 2022-11-28 13:41:30 -05:00
parent 692bd00e46
commit 59aacf05a8
1 changed files with 29 additions and 21 deletions

View File

@ -590,16 +590,12 @@ class ProcessInstanceProcessor:
if self.bpmn_process_instance.is_completed():
self.process_instance_model.end_in_seconds = round(time.time())
active_tasks = ActiveTaskModel.query.filter_by(
process_instance_id=self.process_instance_model.id
).all()
if len(active_tasks) > 0:
for at in active_tasks:
db.session.delete(at)
db.session.add(self.process_instance_model)
db.session.commit()
active_tasks = ActiveTaskModel.query.filter_by(
process_instance_id=self.process_instance_model.id
).all()
ready_or_waiting_tasks = self.get_all_ready_or_waiting_tasks()
for ready_or_waiting_task in ready_or_waiting_tasks:
# filter out non-usertasks
@ -626,6 +622,13 @@ class ProcessInstanceProcessor:
if process_model_info is not None:
process_model_display_name = process_model_info.display_name
active_task = None
for at in active_tasks:
if at.task_id == str(ready_or_waiting_task.id):
active_task = at
active_tasks.pop(at)
if active_task is None:
active_task = ActiveTaskModel(
process_instance_id=self.process_instance_model.id,
process_model_display_name=process_model_display_name,
@ -648,6 +651,11 @@ class ProcessInstanceProcessor:
db.session.add(active_task_user)
db.session.commit()
if len(active_tasks) > 0:
for at in active_tasks:
db.session.delete(at)
db.session.commit()
@staticmethod
def get_parser() -> MyCustomParser:
"""Get_parser."""