diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py b/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py index 68fee58a6..017b6e9d0 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py @@ -1,7 +1,6 @@ """__init__.""" import faulthandler import os -import sys from typing import Any import connexion # type: ignore diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index b9b7a9e35..d472d8147 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -1518,6 +1518,47 @@ paths: items: $ref: "#/components/schemas/Task" + /task-data/{modified_process_model_identifier}/{process_instance_id}: + parameters: + - name: modified_process_model_identifier + in: path + required: true + description: The modified id of an existing process model + schema: + type: string + - name: process_instance_id + in: path + required: true + description: The unique id of an existing process instance. + schema: + type: integer + - name: all_tasks + in: query + required: false + description: If true, this wil return all tasks associated with the process instance and not just user tasks. + schema: + type: boolean + - name: spiff_step + in: query + required: false + description: If set will return the tasks as they were during a specific step of execution. + schema: + type: integer + get: + tags: + - Process Instances + operationId: spiffworkflow_backend.routes.process_instances_controller.process_instance_task_list_with_task_data + summary: returns the list of all user tasks associated with process instance with the task data + responses: + "200": + description: list of tasks + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/Task" + /task-data/{modified_process_model_identifier}/{process_instance_id}/{spiff_step}: parameters: - name: modified_process_model_identifier diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py index 6234c6458..6f2a57af0 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py @@ -514,6 +514,7 @@ def process_instance_task_list_without_task_data_for_me( process_instance, all_tasks, spiff_step, + get_task_data=False, ) @@ -530,6 +531,24 @@ def process_instance_task_list_without_task_data( process_instance, all_tasks, spiff_step, + get_task_data=False, + ) + + +def process_instance_task_list_with_task_data( + modified_process_model_identifier: str, + process_instance_id: int, + all_tasks: bool = False, + spiff_step: int = 0, +) -> flask.wrappers.Response: + """Process_instance_task_list_with_task_data.""" + process_instance = _find_process_instance_by_id_or_raise(process_instance_id) + return process_instance_task_list( + modified_process_model_identifier, + process_instance, + all_tasks, + spiff_step, + get_task_data=True, ) @@ -538,6 +557,7 @@ def process_instance_task_list( process_instance: ProcessInstanceModel, all_tasks: bool = False, spiff_step: int = 0, + get_task_data: bool = False, ) -> flask.wrappers.Response: """Process_instance_task_list.""" step_detail_query = db.session.query(SpiffStepDetailsModel).filter( @@ -556,15 +576,32 @@ def process_instance_task_list( steps_by_id = {step_detail.task_id: step_detail for step_detail in step_details} + # FIXME: never evaluate task data in this call and instead create a new api getter + # that will return the task data for a given step only. We think processing this + # data is what is causing long load times on the processInstanceShowPage. + # TaskShow still uses this to get the data for the tabs. We need to update that as well. subprocess_state_overrides = {} for step_detail in step_details: if step_detail.task_id in tasks: + task_data = ( + step_detail.task_json["task_data"] | step_detail.task_json["python_env"] + ) + if task_data is None: + task_data = {} + tasks[step_detail.task_id]["data"] = task_data tasks[step_detail.task_id]["state"] = Task.task_state_name_to_int( step_detail.task_state ) else: for subprocess_id, subprocess_info in subprocesses.items(): if step_detail.task_id in subprocess_info["tasks"]: + task_data = ( + step_detail.task_json["task_data"] + | step_detail.task_json["python_env"] + ) + if task_data is None: + task_data = {} + subprocess_info["tasks"][step_detail.task_id]["data"] = task_data subprocess_info["tasks"][step_detail.task_id]["state"] = ( Task.task_state_name_to_int(step_detail.task_state) ) @@ -621,6 +658,8 @@ def process_instance_task_list( calling_subprocess_task_id=calling_subprocess_task_id, task_spiff_step=task_spiff_step, ) + if get_task_data: + task.data = spiff_task.data tasks.append(task) return make_response(jsonify(tasks), 200)