Skip to content

Commit

Permalink
get most recent tasks based on last_state_change instead of task_mode…
Browse files Browse the repository at this point in the history
…l.id
  • Loading branch information
jasquat committed Dec 14, 2023
1 parent e161c3d commit 903e421
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def process_instance_task_list_without_task_data_for_me(
to_task_guid: str | None = None,
) -> flask.wrappers.Response:
process_instance = _find_process_instance_for_me_or_raise(process_instance_id)
return process_instance_task_list(
return _process_instance_task_list(
_modified_process_model_identifier=modified_process_model_identifier,
process_instance=process_instance,
most_recent_tasks_only=most_recent_tasks_only,
Expand All @@ -351,7 +351,7 @@ def process_instance_task_list_without_task_data(
to_task_guid: str | None = None,
) -> flask.wrappers.Response:
process_instance = _find_process_instance_by_id_or_raise(process_instance_id)
return process_instance_task_list(
return _process_instance_task_list(
_modified_process_model_identifier=modified_process_model_identifier,
process_instance=process_instance,
most_recent_tasks_only=most_recent_tasks_only,
Expand All @@ -360,7 +360,7 @@ def process_instance_task_list_without_task_data(
)


def process_instance_task_list(
def _process_instance_task_list(
_modified_process_model_identifier: str,
process_instance: ProcessInstanceModel,
bpmn_process_guid: str | None = None,
Expand Down Expand Up @@ -448,11 +448,6 @@ def process_instance_task_list(
BpmnProcessDefinitionModel.bpmn_identifier.label("bpmn_process_definition_identifier"), # type: ignore
BpmnProcessDefinitionModel.bpmn_name.label("bpmn_process_definition_name"), # type: ignore
bpmn_process_alias.guid.label("bpmn_process_guid"),
# not sure why we needed these
# direct_parent_bpmn_process_alias.guid.label("bpmn_process_direct_parent_guid"),
# direct_parent_bpmn_process_definition_alias.bpmn_identifier.label(
# "bpmn_process_direct_parent_bpmn_identifier"
# ),
TaskDefinitionModel.bpmn_identifier,
TaskDefinitionModel.bpmn_name,
TaskDefinitionModel.typename,
Expand All @@ -462,6 +457,7 @@ def process_instance_task_list(
TaskModel.end_in_seconds,
TaskModel.start_in_seconds,
TaskModel.runtime_info,
TaskModel.properties_json,
)
)

Expand All @@ -470,7 +466,7 @@ def process_instance_task_list(

task_models = task_model_query.all()
if most_recent_tasks_only:
most_recent_tasks = {}
most_recent_tasks: dict[str, TaskModel] = {}
additional_tasks = []

# if you have a loop and there is a subprocess, and you are going around for the second time,
Expand All @@ -487,8 +483,15 @@ def process_instance_task_list(
full_bpmn_process_path = bpmn_process_cache[task_model.bpmn_process_guid]

row_key = f"{':::'.join(full_bpmn_process_path)}:::{task_model.bpmn_identifier}"
if row_key not in most_recent_tasks:
if (
row_key not in most_recent_tasks
or most_recent_tasks[row_key].properties_json["last_state_change"]
< task_model.properties_json["last_state_change"]
):
most_recent_tasks[row_key] = task_model

# we may need to remove guids for tasks that are no longer considered most recent but that may not matter
# since any task like would no longer be in the list anyway and therefore will not be returned
if task_model.typename in ["SubWorkflowTask", "CallActivity"]:
relevant_subprocess_guids.add(task_model.guid)
elif task_model.runtime_info and ("instance" in task_model.runtime_info or "iteration" in task_model.runtime_info):
Expand Down

0 comments on commit 903e421

Please sign in to comment.