Skip to content

Commit

Permalink
feature/skip-user-input-required-tasks (#596)
Browse files Browse the repository at this point in the history
* only check for timer events in ready_user_task_has_associated_timer so we can skip user_input_required instances w/ burnettk

* removed test.py file w/ burnettk

---------

Co-authored-by: jasquat <[email protected]>
  • Loading branch information
jasquat and jasquat authored Oct 27, 2023
1 parent aaedd84 commit 64682af
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
15 changes: 15 additions & 0 deletions spiffworkflow-backend/bin/run_local_python_script
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

function error_handler() {
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
exit "$2"
}
trap 'error_handler ${LINENO} $?' ERR
set -o errtrace -o errexit -o nounset -o pipefail

script_dir="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
. "${script_dir}/local_development_environment_setup"

export SPIFFWORKFLOW_BACKEND_RUN_BACKGROUND_SCHEDULER_IN_CREATE_APP=false

poet run python "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from flask import g
from SpiffWorkflow.bpmn.event import PendingBpmnEvent # type: ignore
from SpiffWorkflow.bpmn.specs.control import BoundaryEventSplit # type: ignore
from SpiffWorkflow.bpmn.specs.defaults import BoundaryEvent # type: ignore
from SpiffWorkflow.bpmn.specs.event_definitions.timer import TimerEventDefinition # type: ignore
from SpiffWorkflow.task import Task as SpiffTask # type: ignore
from SpiffWorkflow.util.task import TaskState # type: ignore
Expand Down Expand Up @@ -204,7 +205,13 @@ def all_waiting_events_can_be_skipped(cls, waiting_events: list[dict[str, Any]])
def ready_user_task_has_associated_timer(cls, processor: ProcessInstanceProcessor) -> bool:
for ready_user_task in processor.bpmn_process_instance.get_tasks(state=TaskState.READY, manual=True):
if isinstance(ready_user_task.parent.task_spec, BoundaryEventSplit):
return True
for boundary_event_child in ready_user_task.parent.children:
child_task_spec = boundary_event_child.task_spec
if (
isinstance(child_task_spec, BoundaryEvent)
and "Timer" in child_task_spec.event_definition.__class__.__name__
):
return True
return False

@classmethod
Expand All @@ -215,8 +222,10 @@ def can_optimistically_skip(cls, processor: ProcessInstanceProcessor, status_val
if processor.process_instance_model.status != status_value:
return True

if status_value == "user_input_required" and cls.ready_user_task_has_associated_timer(processor):
return cls.all_waiting_events_can_be_skipped(processor.bpmn_process_instance.waiting_events())
if status_value == "user_input_required":
if cls.ready_user_task_has_associated_timer(processor):
return cls.all_waiting_events_can_be_skipped(processor.bpmn_process_instance.waiting_events())
return True

return False

Expand Down Expand Up @@ -265,6 +274,10 @@ def run_process_instance_with_processor(
processor = ProcessInstanceProcessor(
process_instance, workflow_completed_handler=cls.schedule_next_process_model_cycle
)

# if status_value is user_input_required (we are processing instances with that status from background processor),
# the ONLY reason we need to do anything is if the task has a timer boundary event on it that has triggered.
# otherwise, in all cases, we should optimistically skip it.
if status_value and cls.can_optimistically_skip(processor, status_value):
current_app.logger.info(f"Optimistically skipped process_instance {process_instance.id}")
return None
Expand Down

0 comments on commit 64682af

Please sign in to comment.