wait 120 seconds before processing user_input_required process instances w/ burnettk

This commit is contained in:
jasquat 2023-03-02 12:06:12 -05:00
parent 612d63f141
commit 6e23a179b7
3 changed files with 15 additions and 9 deletions

View File

@ -76,6 +76,11 @@ def start_scheduler(
"interval", "interval",
seconds=10, seconds=10,
) )
scheduler.add_job(
BackgroundProcessingService(app).process_user_input_required_process_instances,
"interval",
seconds=120,
)
scheduler.start() scheduler.start()

View File

@ -1,6 +1,7 @@
"""Background_processing_service.""" """Background_processing_service."""
import flask import flask
from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus
from spiffworkflow_backend.services.message_service import MessageService from spiffworkflow_backend.services.message_service import MessageService
from spiffworkflow_backend.services.process_instance_service import ( from spiffworkflow_backend.services.process_instance_service import (
ProcessInstanceService, ProcessInstanceService,
@ -19,6 +20,13 @@ class BackgroundProcessingService:
with self.app.app_context(): with self.app.app_context():
ProcessInstanceService.do_waiting() 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: def process_message_instances_with_app_context(self) -> None:
"""Since this runs in a scheduler, we need to specify the app context as well.""" """Since this runs in a scheduler, we need to specify the app context as well."""
with self.app.app_context(): with self.app.app_context():

View File

@ -7,7 +7,6 @@ from typing import Optional
import sentry_sdk import sentry_sdk
from flask import current_app from flask import current_app
from SpiffWorkflow.task import Task as SpiffTask # type: ignore from SpiffWorkflow.task import Task as SpiffTask # type: ignore
from sqlalchemy import or_
from spiffworkflow_backend import db from spiffworkflow_backend import db
from spiffworkflow_backend.exceptions.api_error import ApiError from spiffworkflow_backend.exceptions.api_error import ApiError
@ -71,17 +70,11 @@ class ProcessInstanceService:
return cls.create_process_instance(process_model, user) return cls.create_process_instance(process_model, user)
@staticmethod @staticmethod
def do_waiting() -> None: def do_waiting(status_value: str = ProcessInstanceStatus.waiting.value) -> None:
"""Do_waiting.""" """Do_waiting."""
records = ( records = (
db.session.query(ProcessInstanceModel) db.session.query(ProcessInstanceModel)
.filter( .filter(ProcessInstanceModel.status == status_value)
or_(
ProcessInstanceModel.status == ProcessInstanceStatus.waiting.value,
ProcessInstanceModel.status
== ProcessInstanceStatus.user_input_required.value,
)
)
.all() .all()
) )
process_instance_lock_prefix = "Background" process_instance_lock_prefix = "Background"