backend tests are passing with less optimized way

This commit is contained in:
jasquat 2023-04-06 10:30:18 -04:00
parent fa7c4b81e6
commit 0a97239079
No known key found for this signature in database
5 changed files with 73 additions and 45 deletions

View File

@ -135,14 +135,13 @@ class TaskService:
# we are not sure why task_model.bpmn_process can be None while task_model.bpmn_process_id actually has a valid value
bpmn_process = new_bpmn_process or task_model.bpmn_process or BpmnProcessModel.query.filter_by(id=task_model.bpmn_process_id).first()
# if bpmn_process is None:
# import pdb; pdb.set_trace()
# print("HEY")
try:
bpmn_process_json_data = self.__class__.update_task_data_on_bpmn_process(
bpmn_process, spiff_task.workflow.data
)
except Exception as ex:
import pdb; pdb.set_trace()
print("HEY90823")
bpmn_process_json_data = self.__class__.update_task_data_on_bpmn_process(
bpmn_process, spiff_task.workflow.data
)
json_data_dict_list = self.__class__.update_task_model(task_model, spiff_task, self.serializer)
self.task_models[task_model.guid] = task_model
if bpmn_process_json_data is not None:
@ -177,9 +176,14 @@ class TaskService:
spiff_workflow: BpmnWorkflow,
bpmn_process: BpmnProcessModel,
) -> None:
# bpmn_process_dict = self.serializer.workflow_to_dict(spiff_workflow)
new_properties_json = copy.copy(bpmn_process.properties_json)
new_properties_json["last_task"] = str(spiff_workflow.last_task.id) if spiff_workflow.last_task else None
new_properties_json["success"] = spiff_workflow.success
# # update correlations correctly but always null out bpmn_messages since they get cleared out later
# new_properties_json['correlations'] = bpmn_process_dict['correlations']
# new_properties_json['bpmn_messages'] = []
bpmn_process.properties_json = new_properties_json
bpmn_process_json_data = self.__class__.update_task_data_on_bpmn_process(bpmn_process, spiff_workflow.data)
@ -192,6 +196,9 @@ class TaskService:
direct_parent_bpmn_process = BpmnProcessModel.query.filter_by(
id=bpmn_process.direct_parent_process_id
).first()
# if direct_parent_bpmn_process is None:
# import pdb; pdb.set_trace()
# print("HEY22")
self.update_bpmn_process(spiff_workflow.outer_workflow, direct_parent_bpmn_process)
@classmethod

View File

@ -61,8 +61,7 @@ class TaskModelSavingDelegate(EngineStepDelegate):
self.bpmn_definition_to_task_definitions_mappings = bpmn_definition_to_task_definitions_mappings
self.serializer = serializer
self.current_task_model: Optional[TaskModel] = None
# self.current_task_start_in_seconds: Optional[float] = None
self.current_task_start_in_seconds: Optional[float] = None
self.last_completed_spiff_task: Optional[SpiffTask] = None
self.spiff_tasks_to_process: Set[UUID] = set()
@ -78,27 +77,27 @@ class TaskModelSavingDelegate(EngineStepDelegate):
if self._should_update_task_model():
self.spiff_task_timestamps[spiff_task.id] = {'start_in_seconds': time.time(), 'end_in_seconds': None}
spiff_task.task_spec._predict(spiff_task, mask=TaskState.NOT_FINISHED_MASK)
self.current_task_start_in_seconds = time.time()
if self.secondary_engine_step_delegate:
self.secondary_engine_step_delegate.will_complete_task(spiff_task)
def did_complete_task(self, spiff_task: SpiffTask) -> None:
if self._should_update_task_model():
# if spiff_task.task_spec.name == 'test_process_to_call_script.BoundaryEventParent':
# import pdb; pdb.set_trace()
# print("HEY")
# task_model = self.task_service.update_task_model_with_spiff_task(spiff_task)
# if self.current_task_start_in_seconds is None:
# raise Exception("Could not find cached current_task_start_in_seconds. This should never have happend")
# task_model.start_in_seconds = self.current_task_start_in_seconds
# task_model.end_in_seconds = time.time()
task_model = self.task_service.update_task_model_with_spiff_task(spiff_task)
if self.current_task_start_in_seconds is None:
raise Exception("Could not find cached current_task_start_in_seconds. This should never have happend")
task_model.start_in_seconds = self.current_task_start_in_seconds
task_model.end_in_seconds = time.time()
self.spiff_task_timestamps[spiff_task.id]['end_in_seconds'] = time.time()
self.last_completed_spiff_task = spiff_task
self.spiff_tasks_to_process.add(spiff_task.id)
self._add_children(spiff_task)
# self._add_parents(spiff_task)
# self.task_service.process_spiff_task_parent_subprocess_tasks(spiff_task)
# self.task_service.process_spiff_task_children(spiff_task)
self.last_completed_spiff_task = spiff_task
if self.secondary_engine_step_delegate:
self.secondary_engine_step_delegate.did_complete_task(spiff_task)
@ -128,39 +127,50 @@ class TaskModelSavingDelegate(EngineStepDelegate):
def after_engine_steps(self, bpmn_process_instance: BpmnWorkflow) -> None:
if self._should_update_task_model():
# excludes COMPLETED. the others were required to get PP1 to go to completion.
# process FUTURE tasks because Boundary events are not processed otherwise.
# for waiting_spiff_task in bpmn_process_instance.get_tasks(
# TaskState.WAITING | TaskState.CANCELLED | TaskState.READY | TaskState.MAYBE | TaskState.LIKELY | TaskState.FUTURE
# ):
# self.task_service.update_task_model_with_spiff_task(waiting_spiff_task)
for spiff_task_uuid in self.spiff_tasks_to_process:
if spiff_task_uuid is None: # or str(spiff_task_uuid) in self.task_service.task_models:
continue
try:
# print(f"spiff_task_uuid: {spiff_task_uuid}")
waiting_spiff_task = bpmn_process_instance.get_task_from_id(spiff_task_uuid)
except TaskNotFoundException:
continue
# if waiting_spiff_task.task_spec.name == 'top_level_manual_task_two':
# import pdb; pdb.set_trace()
# print("HEY42")
# include PREDICTED_MASK tasks in list so we can remove them from the parent
for waiting_spiff_task in bpmn_process_instance.get_tasks(
TaskState.WAITING | TaskState.CANCELLED | TaskState.READY | TaskState.MAYBE | TaskState.LIKELY | TaskState.FUTURE
# TaskState.WAITING | TaskState.CANCELLED | TaskState.READY | TaskState.MAYBE | TaskState.LIKELY
# TaskState.WAITING | TaskState.CANCELLED | TaskState.READY | TaskState.FUTURE
):
if waiting_spiff_task._has_state(TaskState.PREDICTED_MASK):
TaskService.remove_spiff_task_from_parent(waiting_spiff_task, self.task_service.task_models)
for cpt in waiting_spiff_task.parent.children:
if cpt.id == waiting_spiff_task.id:
waiting_spiff_task.parent.children.remove(cpt)
waiting_spiff_task.parent.children.remove(cpt)
continue
start_and_end_times = None
if waiting_spiff_task.id in self.spiff_task_timestamps:
start_and_end_times = self.spiff_task_timestamps[waiting_spiff_task.id]
self.task_service.update_task_model_with_spiff_task(waiting_spiff_task, start_and_end_times=start_and_end_times)
# self.task_service.process_spiff_task_parent_subprocess_tasks(waiting_spiff_task)
self.task_service.update_task_model_with_spiff_task(waiting_spiff_task)
if self.last_completed_spiff_task is not None:
self.task_service.process_spiff_task_parent_subprocess_tasks(self.last_completed_spiff_task)
# for spiff_task_uuid in self.spiff_tasks_to_process:
# try:
# waiting_spiff_task = bpmn_process_instance.get_task_from_id(spiff_task_uuid)
# except TaskNotFoundException:
# continue
#
# # include PREDICTED_MASK tasks in list so we can remove them from the parent
# if waiting_spiff_task._has_state(TaskState.PREDICTED_MASK):
# TaskService.remove_spiff_task_from_parent(waiting_spiff_task, self.task_service.task_models)
# for cpt in waiting_spiff_task.parent.children:
# if cpt.id == waiting_spiff_task.id:
# waiting_spiff_task.parent.children.remove(cpt)
# continue
# # if waiting_spiff_task.state == TaskState.FUTURE:
# # continue
# start_and_end_times = None
# if waiting_spiff_task.id in self.spiff_task_timestamps:
# start_and_end_times = self.spiff_task_timestamps[waiting_spiff_task.id]
# self.task_service.update_task_model_with_spiff_task(waiting_spiff_task, start_and_end_times=start_and_end_times)
#
# if self.last_completed_spiff_task is not None:
# self.task_service.process_spiff_task_parent_subprocess_tasks(self.last_completed_spiff_task)
# if self.last_completed_spiff_task is not None:
# self.task_service.process_spiff_task_children(self.last_completed_spiff_task)
# self.task_service.process_spiff_task_parent_subprocess_tasks(self.last_completed_spiff_task)
def _should_update_task_model(self) -> bool:
"""We need to figure out if we have previously save task info on this process intance.
@ -312,6 +322,8 @@ class WorkflowExecutionService:
if bpmn_process is not None:
bpmn_process_correlations = self.bpmn_process_instance.correlations
bpmn_process.properties_json["correlations"] = bpmn_process_correlations
# update correlations correctly but always null out bpmn_messages since they get cleared out later
bpmn_process.properties_json["bpmn_messages"] = []
db.session.add(bpmn_process)
db.session.commit()

View File

@ -50,6 +50,9 @@
<bpmn:outgoing>Flow_089aeua</bpmn:outgoing>
<bpmn:script>set_in_test_process_to_call_script = 1</bpmn:script>
</bpmn:scriptTask>
<bpmn:boundaryEvent id="our_boundary_event" name="our_boundary_event" attachedToRef="test_process_to_call_script">
<bpmn:escalationEventDefinition id="EscalationEventDefinition_1bs7saf" />
</bpmn:boundaryEvent>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="test_process_to_call">
@ -66,6 +69,12 @@
<dc:Bounds x="450" y="110" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0wfnf83_di" bpmnElement="our_boundary_event">
<dc:Bounds x="492" y="172" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="467" y="215" width="87" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1qsx5et_di" bpmnElement="Flow_1qsx5et">
<di:waypoint x="198" y="150" />
<di:waypoint x="270" y="150" />

View File

@ -59,7 +59,6 @@ class TestLoggingService(BaseTest):
assert log_response.status_code == 200
assert log_response.json
logs: list = log_response.json["results"]
import pdb; pdb.set_trace()
assert len(logs) == 4
for log in logs:

View File

@ -346,6 +346,7 @@ class TestProcessInstanceProcessor(BaseTest):
ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one)
human_task_one = process_instance.active_human_tasks[0]
spiff_manual_task = processor.bpmn_process_instance.get_task_from_id(UUID(human_task_one.task_id))
# import pdb; pdb.set_trace()
ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one)
processor.suspend()
@ -547,7 +548,7 @@ class TestProcessInstanceProcessor(BaseTest):
all_spiff_tasks = processor_final.bpmn_process_instance.get_tasks()
assert len(all_spiff_tasks) > 1
for spiff_task in all_spiff_tasks:
assert spiff_task.state == TaskState.COMPLETED
assert spiff_task.state == TaskState.COMPLETED or TaskState.CANCELLED
assert_spiff_task_is_in_process(spiff_task)
if spiff_task.task_spec.name == "top_level_call_activity":