Skip to content

Commit

Permalink
Feature/do not save cancelled task events twice (#575)
Browse files Browse the repository at this point in the history
* do not save cancelled task events again

* actually only process cancelled events that were cancelled during the current run

---------

Co-authored-by: jasquat <[email protected]>
  • Loading branch information
jasquat and jasquat authored Oct 25, 2023
1 parent 7642012 commit 6527a1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def update_task_model_with_spiff_task(
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def __init__(
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,
Expand Down Expand Up @@ -250,7 +252,6 @@ def add_object_to_db_session(self, bpmn_process_instance: BpmnWorkflow) -> None:
# 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
Expand All @@ -260,6 +261,18 @@ def add_object_to_db_session(self, bpmn_process_instance: BpmnWorkflow) -> None:
):
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:
Expand Down

0 comments on commit 6527a1a

Please sign in to comment.