From 259290846da150c5b5c3fb5c96ede92be6077eae Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 20 Apr 2023 16:55:13 -0400 Subject: [PATCH] fallout from recent changes to Main. --- .../src/spiffworkflow_backend/config/__init__.py | 12 ++++++------ .../models/process_instance.py | 6 +++--- .../routes/process_instances_controller.py | 2 +- .../services/process_instance_processor.py | 12 ++++++------ .../services/process_instance_service.py | 14 ++++++++------ .../services/workflow_execution_service.py | 8 +++----- .../src/routes/ProcessInterstitial.tsx | 11 +++++++---- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/config/__init__.py b/spiffworkflow-backend/src/spiffworkflow_backend/config/__init__.py index 7711c36f..eaf67f6c 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/config/__init__.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/config/__init__.py @@ -18,13 +18,13 @@ def setup_database_uri(app: Flask) -> None: if app.config.get("SPIFFWORKFLOW_BACKEND_DATABASE_URI") is None: database_name = f"spiffworkflow_backend_{app.config['ENV_IDENTIFIER']}" if app.config.get("SPIFFWORKFLOW_BACKEND_DATABASE_TYPE") == "sqlite": - app.config["SQLALCHEMY_DATABASE_URI"] = ( - f"sqlite:///{app.instance_path}/db_{app.config['ENV_IDENTIFIER']}.sqlite3" - ) + app.config[ + "SQLALCHEMY_DATABASE_URI" + ] = f"sqlite:///{app.instance_path}/db_{app.config['ENV_IDENTIFIER']}.sqlite3" elif app.config.get("SPIFFWORKFLOW_BACKEND_DATABASE_TYPE") == "postgres": - app.config["SQLALCHEMY_DATABASE_URI"] = ( - f"postgresql://spiffworkflow_backend:spiffworkflow_backend@localhost:5432/{database_name}" - ) + app.config[ + "SQLALCHEMY_DATABASE_URI" + ] = f"postgresql://spiffworkflow_backend:spiffworkflow_backend@localhost:5432/{database_name}" else: # use pswd to trick flake8 with hardcoded passwords db_pswd = app.config.get("SPIFFWORKFLOW_BACKEND_DATABASE_PASSWORD") diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance.py index 009a7486..44fe8276 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance.py @@ -127,9 +127,9 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel): def serialized_with_metadata(self) -> dict[str, Any]: process_instance_attributes = self.serialized process_instance_attributes["process_metadata"] = self.process_metadata - process_instance_attributes["process_model_with_diagram_identifier"] = ( - self.process_model_with_diagram_identifier - ) + process_instance_attributes[ + "process_model_with_diagram_identifier" + ] = self.process_model_with_diagram_identifier return process_instance_attributes @property 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 b8217fa3..5b74ba03 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py @@ -124,7 +124,7 @@ def process_instance_run( processor = None try: - processor = ProcessInstanceService.run_process_intance_with_processor(process_instance) + processor = ProcessInstanceService.run_process_instance_with_processor(process_instance) except ( ApiError, ProcessInstanceIsNotEnqueuedError, diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index 224e20fe..3dbe38f7 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -423,9 +423,9 @@ class ProcessInstanceProcessor: tld.process_instance_id = process_instance_model.id # we want this to be the fully qualified path to the process model including all group subcomponents - current_app.config["THREAD_LOCAL_DATA"].process_model_identifier = ( - f"{process_instance_model.process_model_identifier}" - ) + current_app.config[ + "THREAD_LOCAL_DATA" + ].process_model_identifier = f"{process_instance_model.process_model_identifier}" self.process_instance_model = process_instance_model self.process_model_service = ProcessModelService() @@ -585,9 +585,9 @@ class ProcessInstanceProcessor: bpmn_subprocess_definition.bpmn_identifier ] = bpmn_process_definition_dict spiff_bpmn_process_dict["subprocess_specs"][bpmn_subprocess_definition.bpmn_identifier]["task_specs"] = {} - bpmn_subprocess_definition_bpmn_identifiers[bpmn_subprocess_definition.id] = ( - bpmn_subprocess_definition.bpmn_identifier - ) + bpmn_subprocess_definition_bpmn_identifiers[ + bpmn_subprocess_definition.id + ] = bpmn_subprocess_definition.bpmn_identifier task_definitions = TaskDefinitionModel.query.filter( TaskDefinitionModel.bpmn_process_definition_id.in_( # type: ignore diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py index 4774c7e6..220b0afb 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py @@ -115,10 +115,14 @@ class ProcessInstanceService: .filter(ProcessInstanceModel.id.in_(process_instance_ids_to_check)) # type: ignore .all() ) + execution_strategy_name = current_app.config[ + "SPIFFWORKFLOW_BACKEND_ENGINE_STEP_DEFAULT_STRATEGY_BACKGROUND" + ] for process_instance in records: current_app.logger.info(f"Processing process_instance {process_instance.id}") try: - cls.run_process_intance_with_processor(process_instance, status_value=status_value) + cls.run_process_instance_with_processor(process_instance, status_value=status_value, + execution_strategy_name=execution_strategy_name) except ProcessInstanceIsAlreadyLockedError: continue except Exception as e: @@ -130,8 +134,9 @@ class ProcessInstanceService: current_app.logger.error(error_message) @classmethod - def run_process_intance_with_processor( - cls, process_instance: ProcessInstanceModel, status_value: Optional[str] = None + def run_process_instance_with_processor( + cls, process_instance: ProcessInstanceModel, status_value: Optional[str] = None, + execution_strategy_name = None ) -> Optional[ProcessInstanceProcessor]: processor = None with ProcessInstanceQueueService.dequeued(process_instance): @@ -142,9 +147,6 @@ class ProcessInstanceService: db.session.refresh(process_instance) if status_value is None or process_instance.status == status_value: - execution_strategy_name = current_app.config[ - "SPIFFWORKFLOW_BACKEND_ENGINE_STEP_DEFAULT_STRATEGY_BACKGROUND" - ] processor.do_engine_steps(save=True, execution_strategy_name=execution_strategy_name) return processor diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/workflow_execution_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/workflow_execution_service.py index d52892de..dee9317e 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/workflow_execution_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/workflow_execution_service.py @@ -4,9 +4,6 @@ import copy import time from abc import abstractmethod from typing import Callable -from typing import List -from typing import Optional -from typing import Set from uuid import UUID from SpiffWorkflow.bpmn.serializer.workflow import BpmnWorkflowSerializer # type: ignore @@ -93,7 +90,7 @@ class ExecutionStrategy: def save(self, bpmn_process_instance: BpmnWorkflow) -> None: self.delegate.save(bpmn_process_instance) - def get_ready_engine_steps(self, bpmn_process_instance: BpmnWorkflow) -> List[SpiffTask]: + def get_ready_engine_steps(self, bpmn_process_instance: BpmnWorkflow) -> list[SpiffTask]: return list( [ t @@ -102,6 +99,7 @@ class ExecutionStrategy: ] ) + class TaskModelSavingDelegate(EngineStepDelegate): """Engine step delegate that takes care of saving a task model to the database. @@ -302,7 +300,7 @@ class RunUntilServiceTaskExecutionStrategy(ExecutionStrategy): class RunUntilUserTaskOrMessageExecutionStrategy(ExecutionStrategy): """When you want to run tasks until you hit something to report to the end user.""" - def get_engine_steps(self, bpmn_process_instance: BpmnWorkflow) -> List[SpiffTask]: + def get_engine_steps(self, bpmn_process_instance: BpmnWorkflow) -> list[SpiffTask]: return list( [ t diff --git a/spiffworkflow-frontend/src/routes/ProcessInterstitial.tsx b/spiffworkflow-frontend/src/routes/ProcessInterstitial.tsx index df43daf2..b465cf11 100644 --- a/spiffworkflow-frontend/src/routes/ProcessInterstitial.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessInterstitial.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { fetchEventSource } from '@microsoft/fetch-event-source'; // @ts-ignore @@ -40,9 +40,12 @@ export default function ProcessInterstitial() { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); // it is critical to only run this once. - const shouldRedirect = (myTask: ProcessInstanceTask): boolean => { - return myTask && myTask.can_complete && userTasks.includes(myTask.type); - }; + const shouldRedirect = useCallback( + (myTask: ProcessInstanceTask): boolean => { + return myTask && myTask.can_complete && userTasks.includes(myTask.type); + }, + [userTasks] + ); useEffect(() => { // Added this seperate use effect so that the timer interval will be cleared if