Refresh process_instance after obtaining the background lock (#189)

This commit is contained in:
jbirddog 2023-03-20 10:58:43 -04:00 committed by GitHub
parent 7b3eb4730f
commit 0640836b39
1 changed files with 6 additions and 12 deletions

View File

@ -25,7 +25,6 @@ from spiffworkflow_backend.models.process_instance_file_data import (
from spiffworkflow_backend.models.process_model import ProcessModelInfo
from spiffworkflow_backend.models.task import Task
from spiffworkflow_backend.models.user import UserModel
from spiffworkflow_backend.services.assertion_service import safe_assertion
from spiffworkflow_backend.services.authorization_service import AuthorizationService
from spiffworkflow_backend.services.git_service import GitCommandError
from spiffworkflow_backend.services.git_service import GitService
@ -96,13 +95,6 @@ class ProcessInstanceService:
)
process_instance_lock_prefix = "Background"
for process_instance in records:
with safe_assertion(process_instance.status == status_value) as false_assumption:
if false_assumption:
raise AssertionError(
f"Queue assumed process instance {process_instance.id} has status of {status_value} "
f"when it really is {process_instance.status}"
)
locked = False
processor = None
try:
@ -110,10 +102,12 @@ class ProcessInstanceService:
processor = ProcessInstanceProcessor(process_instance)
processor.lock_process_instance(process_instance_lock_prefix)
locked = True
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)
db.session.refresh(process_instance)
if 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)
except ProcessInstanceIsAlreadyLockedError:
continue
except Exception as e: