fix standard loop task serialization (#606)

* fix standard loop task serialization

* lint

---------

Co-authored-by: burnettk <burnettk@users.noreply.github.com>
This commit is contained in:
Kevin Burnett 2023-11-06 12:18:33 -08:00 committed by GitHub
parent 6014f2940d
commit eb13ab843b
2 changed files with 37 additions and 2 deletions

View File

@ -0,0 +1,28 @@
import sys
from spiffworkflow_backend import create_app
from spiffworkflow_backend.models.user import UserModel
from spiffworkflow_backend.services.process_instance_service import ProcessInstanceService
from spiffworkflow_backend.services.user_service import UserService
def main() -> None:
app = create_app()
process_model_identifier = sys.argv[1]
with app.app_context():
user = UserModel.query.first()
if user is None:
username = "testuser"
user = UserService.create_user(username, "service", "service")
process_instance = ProcessInstanceService.create_process_instance_from_process_model_identifier(
process_model_identifier, user
)
execution_strategy_name = app.config["SPIFFWORKFLOW_BACKEND_ENGINE_STEP_DEFAULT_STRATEGY_BACKGROUND"]
ProcessInstanceService.run_process_instance_with_processor(
process_instance, execution_strategy_name=execution_strategy_name
)
if __name__ == "__main__":
main()

View File

@ -41,7 +41,11 @@ from SpiffWorkflow.serializer.exceptions import MissingSpecError # type: ignore
from SpiffWorkflow.spiff.parser.process import SpiffBpmnParser # type: ignore
from SpiffWorkflow.spiff.serializer.config import SPIFF_CONFIG # type: ignore
from SpiffWorkflow.spiff.serializer.task_spec import ServiceTaskConverter # type: ignore
from SpiffWorkflow.spiff.serializer.task_spec import StandardLoopTaskConverter
from SpiffWorkflow.spiff.specs.defaults import ServiceTask # type: ignore
# fix for StandardLoopTask
from SpiffWorkflow.spiff.specs.defaults import StandardLoopTask
from SpiffWorkflow.task import Task as SpiffTask # type: ignore
from SpiffWorkflow.util.deep_merge import DeepMerge # type: ignore
from SpiffWorkflow.util.task import TaskIterator # type: ignore
@ -100,6 +104,8 @@ from spiffworkflow_backend.services.workflow_execution_service import execution_
from spiffworkflow_backend.specs.start_event import StartEvent
from sqlalchemy import and_
SPIFF_CONFIG[StandardLoopTask] = StandardLoopTaskConverter
# this custom converter is just so we use 'ServiceTask' as the typename in the serialization
# rather than 'CustomServiceTask'
@ -108,13 +114,14 @@ class CustomServiceTaskConverter(ServiceTaskConverter): # type: ignore
super().__init__(target_class, registry, typename)
SPIFF_CONFIG[CustomServiceTask] = CustomServiceTaskConverter
del SPIFF_CONFIG[ServiceTask]
SPIFF_CONFIG[StartEvent] = EventConverter
SPIFF_CONFIG[JSONDataStore] = JSONDataStoreConverter
SPIFF_CONFIG[JSONFileDataStore] = JSONFileDataStoreConverter
SPIFF_CONFIG[KKVDataStore] = KKVDataStoreConverter
SPIFF_CONFIG[TypeaheadDataStore] = TypeaheadDataStoreConverter
SPIFF_CONFIG[CustomServiceTask] = CustomServiceTaskConverter
del SPIFF_CONFIG[ServiceTask]
# Sorry about all this crap. I wanted to move this thing to another file, but
# importing a bunch of types causes circular imports.