Feature/run error handler from dequeued (#424)

* run the error handler from the dequeued method instead of marking all failed process instances as error w/ burnettk

* do not commit some_cache_dir w/ burnettk

---------

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
jasquat 2023-08-02 04:35:11 -04:00 committed by GitHub
parent 796dc9dbec
commit 1c84e5bb47
4 changed files with 12 additions and 9 deletions

View File

@ -20,3 +20,4 @@ node_modules
/src/spiffworkflow_backend/config/secrets.py
*null-ls_*
/local_wheels/*.whl
/some_cache_dir

View File

@ -1,11 +1,9 @@
from flask import current_app
from flask import g
from spiffworkflow_backend.models.db import db
from spiffworkflow_backend.models.message_instance import MessageInstanceModel
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus
from spiffworkflow_backend.models.process_model import ProcessModelInfo
from spiffworkflow_backend.services.message_service import MessageService
from spiffworkflow_backend.services.process_model_service import ProcessModelService
@ -57,6 +55,12 @@ class ErrorHandlingService:
process_instance: ProcessInstanceModel,
) -> None:
"""Send a BPMN Message - which may kick off a waiting process."""
# importing here to avoid circular imports since these imports are only needed here at runtime.
# we were not able to figure out which specific import was causing the issue.
from spiffworkflow_backend.models.message_instance import MessageInstanceModel
from spiffworkflow_backend.services.message_service import MessageService
message_text = (
f"There was an exception running process {process_model.id}.\nOriginal Error:\n{error.__repr__()}"
)

View File

@ -4,9 +4,9 @@ from collections.abc import Generator
from spiffworkflow_backend.models.db import db
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus
from spiffworkflow_backend.models.process_instance_event import ProcessInstanceEventType
from spiffworkflow_backend.models.process_instance_queue import ProcessInstanceQueueModel
from spiffworkflow_backend.services.error_handling_service import ErrorHandlingService
from spiffworkflow_backend.services.process_instance_lock_service import ProcessInstanceLockService
from spiffworkflow_backend.services.process_instance_tmp_service import ProcessInstanceTmpService
from spiffworkflow_backend.services.workflow_execution_service import WorkflowExecutionServiceError
@ -97,15 +97,13 @@ class ProcessInstanceQueueService:
try:
yield
except Exception as ex:
process_instance.status = ProcessInstanceStatus.error.value
db.session.add(process_instance)
# these events are handled in the WorkflowExecutionService.
# that is, we don't need to add error_detail records here, etc.
if not isinstance(ex, WorkflowExecutionServiceError):
ProcessInstanceTmpService.add_event_to_process_instance(
process_instance, ProcessInstanceEventType.process_instance_error.value, exception=ex
)
db.session.commit()
ErrorHandlingService.handle_error(process_instance, ex)
raise ex
finally:
if not reentering_lock:

View File

@ -6,7 +6,6 @@ from spiffworkflow_backend.models.message_instance import MessageInstanceModel
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus
from spiffworkflow_backend.models.process_model import ProcessModelInfo
from spiffworkflow_backend.services.error_handling_service import ErrorHandlingService
from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor
from spiffworkflow_backend.services.process_model_service import ProcessModelService
from spiffworkflow_backend.services.workflow_execution_service import WorkflowExecutionServiceError
@ -24,9 +23,10 @@ class TestErrorHandlingService(BaseTest):
def run_process_model_and_handle_error(self, process_model: ProcessModelInfo) -> ProcessInstanceModel:
process_instance = self.create_process_instance_from_process_model(process_model)
pip = ProcessInstanceProcessor(process_instance)
with pytest.raises(WorkflowExecutionServiceError) as e:
# the error handler will be called from dequeued within do_engine_steps now
with pytest.raises(WorkflowExecutionServiceError):
pip.do_engine_steps(save=True)
ErrorHandlingService().handle_error(process_instance, e.value)
return process_instance
def test_handle_error_suspends_or_faults_process(