Skip to content

Commit

Permalink
remove tasks from the db that were removed in the migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jasquat committed Jul 16, 2024
1 parent 9224fbb commit 249aac1
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 30 deletions.
31 changes: 7 additions & 24 deletions spiffworkflow-backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from spiffworkflow_backend.exceptions.error import ProcessInstanceMigrationUnnecessaryError
from spiffworkflow_backend.exceptions.error import UserDoesNotHaveAccessToTaskError
from spiffworkflow_backend.helpers.spiff_enum import ProcessInstanceExecutionMode
from spiffworkflow_backend.models.bpmn_process import BpmnProcessModel
from spiffworkflow_backend.models.bpmn_process_definition import BpmnProcessDefinitionModel
from spiffworkflow_backend.models.db import db
from spiffworkflow_backend.models.group import GroupModel
Expand Down Expand Up @@ -229,10 +230,13 @@ def migrate_process_instance(
subprocesses_diffs,
) = cls.check_process_instance_can_be_migrated(process_instance, target_bpmn_process_hash=target_bpmn_process_hash)

# does this get from subprocesses as well?
pre_migration_tasks = processor.bpmn_process_instance.get_tasks()
migrate_workflow(top_level_bpmn_process_diff, processor.bpmn_process_instance, target_bpmn_process_spec)
for sp_id, sp in processor.bpmn_process_instance.subprocesses.items():
migrate_workflow(subprocesses_diffs[sp_id], sp, target_subprocess_specs.get(sp.spec.name))
processor.bpmn_process_instance.subprocess_specs = target_subprocess_specs
post_migration_tasks = processor.bpmn_process_instance.get_tasks()

if preserve_old_process_instance:
# TODO: write tests for this code path - no one has a requirement for it yet
Expand Down Expand Up @@ -279,6 +283,16 @@ def migrate_process_instance(
"target_bpmn_process_hash": target_bpmn_process_hash or "",
},
)
pre_task_guids = [str(t.id) for t in pre_migration_tasks]
post_task_guids = [str(t.id) for t in post_migration_tasks]
task_guid_diff = set(pre_task_guids) - set(post_task_guids)
tasks_to_delete = TaskModel.query.filter(TaskModel.guid.in_(task_guid_diff)).all() # type: ignore
bpmn_processes_to_delete = BpmnProcessModel.query.filter(BpmnProcessModel.guid.in_(task_guid_diff)).all() # type: ignore
for td in tasks_to_delete:
db.session.delete(td)
for bpd in bpmn_processes_to_delete:
db.session.delete(bpd)

db.session.commit()

@classmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:spiffworkflow="http://spiffworkflow.org/bpmn/schema/1.0/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_96f6665" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.0.0-dev">
<bpmn:process id="Test_Timer_intermediate_catch" name="Unit Test Timer Event" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1khppaq</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_1khppaq" sourceRef="StartEvent_1" targetRef="Activity_1kvg2ub" />
<bpmn:scriptTask id="Activity_1kvg2ub" name="Get Start Time">
<bpmn:extensionElements>
<spiffworkflow:instructionsForEndUser />
</bpmn:extensionElements>
<bpmn:incoming>Flow_1khppaq</bpmn:incoming>
<bpmn:outgoing>Flow_1if3wm0</bpmn:outgoing>
<bpmn:script>start_time = round(time.time() * 1000)</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_1if3wm0" sourceRef="Activity_1kvg2ub" targetRef="Event_0v3o4zn" />
<bpmn:intermediateCatchEvent id="TimerEvent1">
<bpmn:incoming>Flow_0t0n0qg</bpmn:incoming>
<bpmn:outgoing>Flow_116lqvv</bpmn:outgoing>
<bpmn:timerEventDefinition id="TimerEventDefinition_01q1jut">
<bpmn:timeCycle xsi:type="bpmn:tFormalExpression">"R2/PT60S"</bpmn:timeCycle>
</bpmn:timerEventDefinition>
</bpmn:intermediateCatchEvent>
<bpmn:sequenceFlow id="Flow_116lqvv" sourceRef="TimerEvent1" targetRef="Event_11t2rlx" />
<bpmn:scriptTask id="Activity_1wtffcs" name="Get End Time">
<bpmn:incoming>Flow_0feo9sn</bpmn:incoming>
<bpmn:outgoing>Flow_1gbrmax</bpmn:outgoing>
<bpmn:script>end_time = round(time.time() * 1000)
duration = round((end_time-start_time)/1000)</bpmn:script>
</bpmn:scriptTask>
<bpmn:endEvent id="Event_11isusg">
<bpmn:extensionElements>
<spiffworkflow:instructionsForEndUser>Duration: {{duration}}</spiffworkflow:instructionsForEndUser>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1gbrmax</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1gbrmax" sourceRef="Activity_1wtffcs" targetRef="Event_11isusg" />
<bpmn:intermediateThrowEvent id="Event_0v3o4zn" name="Start">
<bpmn:incoming>Flow_1if3wm0</bpmn:incoming>
<bpmn:outgoing>Flow_0t0n0qg</bpmn:outgoing>
</bpmn:intermediateThrowEvent>
<bpmn:sequenceFlow id="Flow_0t0n0qg" sourceRef="Event_0v3o4zn" targetRef="TimerEvent1" />
<bpmn:intermediateThrowEvent id="Event_11t2rlx" name="End">
<bpmn:incoming>Flow_116lqvv</bpmn:incoming>
<bpmn:outgoing>Flow_0feo9sn</bpmn:outgoing>
</bpmn:intermediateThrowEvent>
<bpmn:sequenceFlow id="Flow_0feo9sn" sourceRef="Event_11t2rlx" targetRef="Activity_1wtffcs" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Test_Timer_intermediate_catch">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="-8" y="159" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1937awy_di" bpmnElement="Activity_1kvg2ub">
<dc:Bounds x="80" y="137" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_17n2nv0_di" bpmnElement="TimerEvent1">
<dc:Bounds x="432" y="159" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1ne1ysk_di" bpmnElement="Activity_1wtffcs">
<dc:Bounds x="560" y="137" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_11isusg_di" bpmnElement="Event_11isusg">
<dc:Bounds x="742" y="159" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0v3o4zn_di" bpmnElement="Event_0v3o4zn">
<dc:Bounds x="372" y="159" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="378" y="202" width="25" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_11t2rlx_di" bpmnElement="Event_11t2rlx">
<dc:Bounds x="492" y="159" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="500" y="202" width="20" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1khppaq_di" bpmnElement="Flow_1khppaq">
<di:waypoint x="28" y="177" />
<di:waypoint x="80" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1if3wm0_di" bpmnElement="Flow_1if3wm0">
<di:waypoint x="180" y="177" />
<di:waypoint x="372" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_116lqvv_di" bpmnElement="Flow_116lqvv">
<di:waypoint x="468" y="177" />
<di:waypoint x="492" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1gbrmax_di" bpmnElement="Flow_1gbrmax">
<di:waypoint x="660" y="177" />
<di:waypoint x="742" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0t0n0qg_di" bpmnElement="Flow_0t0n0qg">
<di:waypoint x="408" y="177" />
<di:waypoint x="432" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0feo9sn_di" bpmnElement="Flow_0feo9sn">
<di:waypoint x="528" y="177" />
<di:waypoint x="560" y="177" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Loading

0 comments on commit 249aac1

Please sign in to comment.