do not store pi events when running migrations (#1310)

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
jasquat 2024-04-01 16:24:02 +00:00 committed by GitHub
parent d8d9cfe89f
commit cef93033e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 4 deletions

View File

@ -20,7 +20,10 @@ class Version4(DataMigrationBase):
bpmn_process_dict = processor.serialize() bpmn_process_dict = processor.serialize()
update_data_objects(bpmn_process_dict) update_data_objects(bpmn_process_dict)
ProcessInstanceProcessor.persist_bpmn_process_dict( ProcessInstanceProcessor.persist_bpmn_process_dict(
bpmn_process_dict, bpmn_definition_to_task_definitions_mappings={}, process_instance_model=process_instance bpmn_process_dict,
bpmn_definition_to_task_definitions_mappings={},
process_instance_model=process_instance,
store_process_instance_events=False,
) )
except Exception as ex: except Exception as ex:

View File

@ -498,6 +498,7 @@ class ProcessInstanceProcessor:
bpmn_process_dict: dict, bpmn_process_dict: dict,
bpmn_definition_to_task_definitions_mappings: dict, bpmn_definition_to_task_definitions_mappings: dict,
process_instance_model: ProcessInstanceModel, process_instance_model: ProcessInstanceModel,
store_process_instance_events: bool = True,
) -> None: ) -> None:
cls._add_bpmn_process_definitions( cls._add_bpmn_process_definitions(
bpmn_process_dict, bpmn_process_dict,
@ -516,7 +517,9 @@ class ProcessInstanceProcessor:
bpmn_process_instance = cls._serializer.from_dict(process_copy) bpmn_process_instance = cls._serializer.from_dict(process_copy)
bpmn_process_instance.script_engine = cls._default_script_engine bpmn_process_instance.script_engine = cls._default_script_engine
for spiff_task in bpmn_process_instance.get_tasks(): for spiff_task in bpmn_process_instance.get_tasks():
task_service.update_task_model_with_spiff_task(spiff_task) task_service.update_task_model_with_spiff_task(
spiff_task, store_process_instance_events=store_process_instance_events
)
task_service.save_objects_to_database() task_service.save_objects_to_database()
db.session.commit() db.session.commit()

View File

@ -187,6 +187,7 @@ class TaskService:
self, self,
spiff_task: SpiffTask, spiff_task: SpiffTask,
start_and_end_times: StartAndEndTimes | None = None, start_and_end_times: StartAndEndTimes | None = None,
store_process_instance_events: bool = True,
) -> TaskModel: ) -> TaskModel:
new_bpmn_process = None new_bpmn_process = None
if str(spiff_task.id) in self.task_models: if str(spiff_task.id) in self.task_models:
@ -216,8 +217,10 @@ class TaskService:
# let failed tasks raise and we will log the event then. # let failed tasks raise and we will log the event then.
# avoid creating events for the same state transition multiple times to avoid multiple cancelled events # avoid creating events for the same state transition multiple times to avoid multiple cancelled events
if task_model.state in ["COMPLETED", "CANCELLED"] and ( if (
self.run_started_at is None or spiff_task.last_state_change >= self.run_started_at store_process_instance_events
and task_model.state in ["COMPLETED", "CANCELLED"]
and (self.run_started_at is None or spiff_task.last_state_change >= self.run_started_at)
): ):
event_type = ProcessInstanceEventType.task_completed.value event_type = ProcessInstanceEventType.task_completed.value
if task_model.state == "CANCELLED": if task_model.state == "CANCELLED":

View File

@ -11,6 +11,7 @@ from spiffworkflow_backend.data_migrations.version_4 import Version4
from spiffworkflow_backend.models.bpmn_process import BpmnProcessModel from spiffworkflow_backend.models.bpmn_process import BpmnProcessModel
from spiffworkflow_backend.models.db import db from spiffworkflow_backend.models.db import db
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
from spiffworkflow_backend.models.process_instance_event import ProcessInstanceEventModel
from spiffworkflow_backend.models.task import TaskModel # noqa: F401 from spiffworkflow_backend.models.task import TaskModel # noqa: F401
from spiffworkflow_backend.models.task_definition import TaskDefinitionModel from spiffworkflow_backend.models.task_definition import TaskDefinitionModel
from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor
@ -119,6 +120,8 @@ class TestProcessInstanceMigrator(BaseTest):
"bpmn_process_id": process_instance.bpmn_process_id, "bpmn_process_id": process_instance.bpmn_process_id,
} }
process_instance_events = ProcessInstanceEventModel.query.filter_by(process_instance_id=process_instance.id).all()
pi_events_count_before = len(process_instance_events)
Version4.run(process_instance) Version4.run(process_instance)
update_data_objects(bpmn_process_dict_version_4_from_spiff) update_data_objects(bpmn_process_dict_version_4_from_spiff)
process_instance = ProcessInstanceModel.query.filter_by(id=process_instance.id).first() process_instance = ProcessInstanceModel.query.filter_by(id=process_instance.id).first()
@ -152,3 +155,7 @@ class TestProcessInstanceMigrator(BaseTest):
for bpmn_process in bpmn_processes: for bpmn_process in bpmn_processes:
for task_model in bpmn_process.tasks: for task_model in bpmn_process.tasks:
assert task_model.task_definition.bpmn_process_definition_id == bpmn_process.bpmn_process_definition_id assert task_model.task_definition.bpmn_process_definition_id == bpmn_process.bpmn_process_definition_id
process_instance_events = ProcessInstanceEventModel.query.filter_by(process_instance_id=process_instance.id).all()
pi_events_count_after = len(process_instance_events)
assert pi_events_count_before == pi_events_count_after