From 7dc15fbebbdd25b7915659345e48b23a8111d975 Mon Sep 17 00:00:00 2001 From: jasquat <2487833+jasquat@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:20:29 -0400 Subject: [PATCH] queue process instances from the apscheduler instead of running them when using celery (#1855) Co-authored-by: jasquat --- .../services/process_instance_service.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 3926f5f0..bfefe0dd 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py @@ -19,6 +19,9 @@ from SpiffWorkflow.task import Task as SpiffTask # type: ignore from SpiffWorkflow.util.deep_merge import DeepMerge # type: ignore from SpiffWorkflow.util.task import TaskState # type: ignore +from spiffworkflow_backend.background_processing.celery_tasks.process_instance_task_producer import ( + queue_process_instance_if_appropriate, +) from spiffworkflow_backend.background_processing.celery_tasks.process_instance_task_producer import should_queue_process_instance from spiffworkflow_backend.data_migrations.process_instance_migrator import ProcessInstanceMigrator from spiffworkflow_backend.exceptions.api_error import ApiError @@ -259,9 +262,10 @@ class ProcessInstanceService: for process_instance in records: current_app.logger.info(f"Processor {status_value}: Processing process_instance {process_instance.id}") try: - cls.run_process_instance_with_processor( - process_instance, status_value=status_value, execution_strategy_name=execution_strategy_name - ) + if not queue_process_instance_if_appropriate(process_instance): + cls.run_process_instance_with_processor( + process_instance, status_value=status_value, execution_strategy_name=execution_strategy_name + ) except ProcessInstanceIsAlreadyLockedError: # we will try again later continue