diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py b/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py index 36749deb3..0fc3d0496 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py @@ -76,6 +76,11 @@ def start_scheduler( "interval", seconds=10, ) + scheduler.add_job( + BackgroundProcessingService(app).process_user_input_required_process_instances, + "interval", + seconds=120, + ) scheduler.start() diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/background_processing_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/background_processing_service.py index 0a2b287b9..dc7e1e7ef 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/background_processing_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/background_processing_service.py @@ -1,6 +1,7 @@ """Background_processing_service.""" import flask +from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus from spiffworkflow_backend.services.message_service import MessageService from spiffworkflow_backend.services.process_instance_service import ( ProcessInstanceService, @@ -19,6 +20,13 @@ class BackgroundProcessingService: with self.app.app_context(): ProcessInstanceService.do_waiting() + def process_user_input_required_process_instances(self) -> None: + """Since this runs in a scheduler, we need to specify the app context as well.""" + with self.app.app_context(): + ProcessInstanceService.do_waiting( + ProcessInstanceStatus.user_input_required.value + ) + def process_message_instances_with_app_context(self) -> None: """Since this runs in a scheduler, we need to specify the app context as well.""" with self.app.app_context(): 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 3e96dab00..d49e93f36 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py @@ -7,7 +7,6 @@ from typing import Optional import sentry_sdk from flask import current_app from SpiffWorkflow.task import Task as SpiffTask # type: ignore -from sqlalchemy import or_ from spiffworkflow_backend import db from spiffworkflow_backend.exceptions.api_error import ApiError @@ -71,17 +70,11 @@ class ProcessInstanceService: return cls.create_process_instance(process_model, user) @staticmethod - def do_waiting() -> None: + def do_waiting(status_value: str = ProcessInstanceStatus.waiting.value) -> None: """Do_waiting.""" records = ( db.session.query(ProcessInstanceModel) - .filter( - or_( - ProcessInstanceModel.status == ProcessInstanceStatus.waiting.value, - ProcessInstanceModel.status - == ProcessInstanceStatus.user_input_required.value, - ) - ) + .filter(ProcessInstanceModel.status == status_value) .all() ) process_instance_lock_prefix = "Background"