From cf9b796e1a659af59f698c2560a8e63b57a503c1 Mon Sep 17 00:00:00 2001 From: jasquat Date: Thu, 2 Mar 2023 10:00:08 -0500 Subject: [PATCH 1/2] avoid creating new processors if it is not necessary --- .../bin/get_bpmn_json_for_process_instance | 11 +++++++++-- .../routes/process_instances_controller.py | 6 ++---- .../routes/tasks_controller.py | 8 +++++--- .../services/process_instance_processor.py | 18 ++++++++++-------- .../integration/test_process_api.py | 4 ++-- 5 files changed, 28 insertions(+), 19 deletions(-) mode change 100644 => 100755 spiffworkflow-backend/bin/get_bpmn_json_for_process_instance diff --git a/spiffworkflow-backend/bin/get_bpmn_json_for_process_instance b/spiffworkflow-backend/bin/get_bpmn_json_for_process_instance old mode 100644 new mode 100755 index d4e3d8ed0..c6f6588f6 --- a/spiffworkflow-backend/bin/get_bpmn_json_for_process_instance +++ b/spiffworkflow-backend/bin/get_bpmn_json_for_process_instance @@ -1,9 +1,14 @@ +#!/usr/bin/env python +# ^ for syntax highlighting + """Get the bpmn process json for a given process instance id and store it in /tmp.""" import os import sys +import json from spiffworkflow_backend import create_app from spiffworkflow_backend.models.process_instance import ProcessInstanceModel +from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor def main(process_instance_id: str): @@ -19,7 +24,7 @@ def main(process_instance_id: str): id=process_instance_id ).first() - file_path = f"/tmp/{process_instance_id}_bpmn_json.json" + file_path = f"/var/tmp/{process_instance_id}_bpmn_json.json" if not process_instance: raise Exception( f"Could not find a process instance with id: {process_instance_id}" @@ -28,7 +33,9 @@ def main(process_instance_id: str): with open( file_path, "w", encoding="utf-8" ) as f: - f.write(process_instance.bpmn_json) + f.write( + json.dumps(ProcessInstanceProcessor._get_full_bpmn_json(process_instance)) + ) print(f"Saved to {file_path}") 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 5862b7c17..918d1749e 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py @@ -167,8 +167,7 @@ def process_instance_suspend( ) -> flask.wrappers.Response: """Process_instance_suspend.""" process_instance = _find_process_instance_by_id_or_raise(process_instance_id) - processor = ProcessInstanceProcessor(process_instance) - processor.suspend() + ProcessInstanceProcessor.suspend(process_instance) return Response(json.dumps({"ok": True}), status=200, mimetype="application/json") @@ -178,8 +177,7 @@ def process_instance_resume( ) -> flask.wrappers.Response: """Process_instance_resume.""" process_instance = _find_process_instance_by_id_or_raise(process_instance_id) - processor = ProcessInstanceProcessor(process_instance) - processor.resume() + ProcessInstanceProcessor.resume(process_instance) return Response(json.dumps({"ok": True}), status=200, mimetype="application/json") diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py index 2555da013..325f32218 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py @@ -254,7 +254,10 @@ def task_show(process_instance_id: int, task_id: str) -> flask.wrappers.Response form_schema_file_name = "" form_ui_schema_file_name = "" - spiff_task = _get_spiff_task_from_process_instance(task_id, process_instance) + processor = ProcessInstanceProcessor(process_instance) + spiff_task = _get_spiff_task_from_process_instance( + task_id, process_instance, processor=processor + ) extensions = spiff_task.task_spec.extensions if "properties" in extensions: @@ -263,7 +266,6 @@ def task_show(process_instance_id: int, task_id: str) -> flask.wrappers.Response form_schema_file_name = properties["formJsonSchemaFilename"] if "formUiSchemaFilename" in properties: form_ui_schema_file_name = properties["formUiSchemaFilename"] - processor = ProcessInstanceProcessor(process_instance) task = ProcessInstanceService.spiff_task_to_api_task(processor, spiff_task) task.data = spiff_task.data task.process_model_display_name = process_model.display_name @@ -612,7 +614,7 @@ def _render_jinja_template(unprocessed_template: str, spiff_task: SpiffTask) -> ) raise wfe from template_error except Exception as error: - type, value, tb = exc_info() + _type, _value, tb = exc_info() wfe = WorkflowTaskException(str(error), task=spiff_task, exception=error) while tb: if tb.tb_frame.f_code.co_filename == "