From 02db5acf6e9fdfa34508a2202d3c6b26d36a54d1 Mon Sep 17 00:00:00 2001 From: Jon Herron Date: Wed, 22 Feb 2023 11:17:23 -0500 Subject: [PATCH] Unfactor to fix size calculation/type hint issues --- .../scripts/get_data_sizes.py | 15 +++++++------ .../services/process_instance_processor.py | 22 +++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/spiffworkflow_backend/scripts/get_data_sizes.py b/src/spiffworkflow_backend/scripts/get_data_sizes.py index 2f28ffa7..94dd2fd6 100644 --- a/src/spiffworkflow_backend/scripts/get_data_sizes.py +++ b/src/spiffworkflow_backend/scripts/get_data_sizes.py @@ -22,7 +22,8 @@ class GetDataSizes(Script): def get_description(self) -> str: """Get_description.""" - return """Returns a dictionary of information about the size of task data and the python environment for the currently running process.""" + return """Returns a dictionary of information about the size of task data and + the python environment for the currently running process.""" def run( self, @@ -32,11 +33,11 @@ class GetDataSizes(Script): ) -> Any: """Run.""" task = script_attributes_context.task + cumulative_task_data_size = ProcessInstanceProcessor.get_task_data_size( + task.workflow + ) + python_env_size = ProcessInstanceProcessor.get_python_env_size(task.workflow) return { - "cumulative_task_data_size": ProcessInstanceProcessor.get_task_data_size( - task.workflow - ), - "python_env_size": ProcessInstanceProcessor.get_python_env_size( - task.workflow - ), + "cumulative_task_data_size": cumulative_task_data_size, + "python_env_size": python_env_size, } diff --git a/src/spiffworkflow_backend/services/process_instance_processor.py b/src/spiffworkflow_backend/services/process_instance_processor.py index 0d0a641e..5b728cd6 100644 --- a/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/src/spiffworkflow_backend/services/process_instance_processor.py @@ -1607,27 +1607,27 @@ class ProcessInstanceProcessor: except WorkflowTaskException as we: raise ApiError.from_workflow_exception("task_error", str(we), we) from we - @classmethod - def _get_data_size(cls, data: Dict[Any, Any]) -> int: - data_to_check = list(filter(len, data)) - - try: - return len(json.dumps(data_to_check)) - except Exception: - return 0 - @classmethod def get_task_data_size(cls, bpmn_process_instance: BpmnWorkflow) -> int: tasks_to_check = bpmn_process_instance.get_tasks(TaskState.FINISHED_MASK) task_data = [task.data for task in tasks_to_check] - return cls._get_data_size(task_data) + task_data_to_check = list(filter(len, task_data)) + + try: + return len(json.dumps(task_data_to_check)) + except Exception: + return 0 @classmethod def get_python_env_size(cls, bpmn_process_instance: BpmnWorkflow) -> int: user_defined_state = ( bpmn_process_instance.script_engine.environment.user_defined_state() ) - return cls._get_data_size(user_defined_state) + + try: + return len(json.dumps(user_defined_state)) + except Exception: + return 0 def check_task_data_size(self) -> None: """CheckTaskDataSize."""