Allow cycle timers to cycle when a human task is in play (#465)

* Refactor to prep for manual task handling

* Fix for manual tasks that complete workflows with cycle timer events

* Getting bin_pyl to pass
This commit is contained in:
jbirddog 2023-09-07 13:40:38 -04:00 committed by GitHub
parent 81baf28d51
commit 2a1e7c8949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -717,7 +717,9 @@ def _task_submit_shared(
status_code=400,
)
processor = ProcessInstanceProcessor(process_instance)
processor = ProcessInstanceProcessor(
process_instance, workflow_completed_handler=ProcessInstanceService.schedule_next_process_model_cycle
)
spiff_task = _get_spiff_task_from_process_instance(task_guid, process_instance, processor=processor)
AuthorizationService.assert_user_can_complete_task(process_instance.id, str(spiff_task.id), principal.user)

View File

@ -96,6 +96,8 @@ TypeaheadDataStore.register_converter(SPIFF_SPEC_CONFIG)
# Sorry about all this crap. I wanted to move this thing to another file, but
# importing a bunch of types causes circular imports.
WorkflowCompletedHandler = Callable[[ProcessInstanceModel], None]
def _import(name: str, glbls: dict[str, Any], *args: Any) -> None:
if name not in glbls:
@ -398,9 +400,11 @@ class ProcessInstanceProcessor:
process_instance_model: ProcessInstanceModel,
validate_only: bool = False,
script_engine: PythonScriptEngine | None = None,
workflow_completed_handler: WorkflowCompletedHandler | None = None,
) -> None:
"""Create a Workflow Processor based on the serialized information available in the process_instance model."""
self._script_engine = script_engine or self.__class__._default_script_engine
self._workflow_completed_handler = workflow_completed_handler
self.setup_processor_with_process_instance(
process_instance_model=process_instance_model, validate_only=validate_only
)
@ -1025,6 +1029,8 @@ class ProcessInstanceProcessor:
if self.process_instance_model.end_in_seconds is None:
if self.bpmn_process_instance.is_completed():
self.process_instance_model.end_in_seconds = round(time.time())
if self._workflow_completed_handler is not None:
self._workflow_completed_handler(self.process_instance_model)
db.session.add(self.process_instance_model)
db.session.commit()

View File

@ -239,8 +239,6 @@ class ProcessInstanceService:
cls.run_process_instance_with_processor(
process_instance, status_value=status_value, execution_strategy_name=execution_strategy_name
)
if process_instance.status == "complete":
cls.schedule_next_process_model_cycle(process_instance)
except ProcessInstanceIsAlreadyLockedError:
continue
except Exception as e:
@ -260,7 +258,9 @@ class ProcessInstanceService:
) -> ProcessInstanceProcessor | None:
processor = None
with ProcessInstanceQueueService.dequeued(process_instance):
processor = ProcessInstanceProcessor(process_instance)
processor = ProcessInstanceProcessor(
process_instance, workflow_completed_handler=cls.schedule_next_process_model_cycle
)
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