Feature/do not save cancelled task events twice (#575)
* do not save cancelled task events again * actually only process cancelled events that were cancelled during the current run --------- Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
parent
16ae1d9ccd
commit
c18c5a8d9c
|
@ -213,6 +213,7 @@ class TaskService:
|
|||
event_type = ProcessInstanceEventType.task_completed.value
|
||||
if task_model.state == "CANCELLED":
|
||||
event_type = ProcessInstanceEventType.task_cancelled.value
|
||||
|
||||
timestamp = task_model.end_in_seconds or task_model.start_in_seconds or time.time()
|
||||
(
|
||||
process_instance_event,
|
||||
|
|
|
@ -201,6 +201,8 @@ class TaskModelSavingDelegate(EngineStepDelegate):
|
|||
self.spiff_tasks_to_process: set[UUID] = set()
|
||||
self.spiff_task_timestamps: dict[UUID, StartAndEndTimes] = {}
|
||||
|
||||
self.run_started_at = time.time()
|
||||
|
||||
self.task_service = TaskService(
|
||||
process_instance=self.process_instance,
|
||||
serializer=self.serializer,
|
||||
|
@ -250,7 +252,6 @@ class TaskModelSavingDelegate(EngineStepDelegate):
|
|||
# 1ead87b4b496525df8cc0e27836c3e987d593dc0 if you are curious.
|
||||
for waiting_spiff_task in bpmn_process_instance.get_tasks(
|
||||
state=TaskState.WAITING
|
||||
| TaskState.CANCELLED
|
||||
| TaskState.READY
|
||||
| TaskState.MAYBE
|
||||
| TaskState.LIKELY
|
||||
|
@ -260,6 +261,18 @@ class TaskModelSavingDelegate(EngineStepDelegate):
|
|||
):
|
||||
self.task_service.update_task_model_with_spiff_task(waiting_spiff_task)
|
||||
|
||||
# only process cancelled tasks that were cancelled during this run
|
||||
# NOTE: this could mean we do not add task models that we should be adding
|
||||
# in which case we may have to remove the updated_ts filter here and
|
||||
# instead just avoid creating the event in update_task_model_with_spiff_task
|
||||
cancelled_spiff_tasks = bpmn_process_instance.get_tasks(
|
||||
state=TaskState.CANCELLED, updated_ts=self.run_started_at
|
||||
)
|
||||
for cancelled_spiff_task in cancelled_spiff_tasks:
|
||||
self.task_service.update_task_model_with_spiff_task(
|
||||
spiff_task=cancelled_spiff_task,
|
||||
)
|
||||
|
||||
self.task_service.save_objects_to_database()
|
||||
|
||||
if self.secondary_engine_step_delegate:
|
||||
|
|
Loading…
Reference in New Issue