From cc43ec55105645584626257b50d573afecc9d823 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Thu, 23 Jun 2022 15:21:54 -0400 Subject: [PATCH] Change process_instance.status column to string Add `faulted` and `suspended` to ProcessInstanceStatus Fix services and models to match this change --- migrations/versions/26094f78f273_.py | 2 +- src/spiffworkflow_backend/api.yml | 2 +- src/spiffworkflow_backend/models/process_instance.py | 9 +++++---- src/spiffworkflow_backend/models/process_model.py | 2 +- .../services/process_instance_processor.py | 2 +- .../services/process_instance_service.py | 2 +- .../integration/test_process_api.py | 4 ++-- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/migrations/versions/26094f78f273_.py b/migrations/versions/26094f78f273_.py index 7bbb2d40..24b50686 100644 --- a/migrations/versions/26094f78f273_.py +++ b/migrations/versions/26094f78f273_.py @@ -60,7 +60,7 @@ def upgrade(): sa.Column('end_in_seconds', sa.Integer(), nullable=True), sa.Column('updated_at_in_seconds', sa.Integer(), nullable=True), sa.Column('created_at_in_seconds', sa.Integer(), nullable=True), - sa.Column('status', sa.Enum('not_started', 'user_input_required', 'waiting', 'complete', 'erroring', name='processinstancestatus'), nullable=True), + sa.Column('status', sa.String(length=50), nullable=True), sa.ForeignKeyConstraint(['process_initiator_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) diff --git a/src/spiffworkflow_backend/api.yml b/src/spiffworkflow_backend/api.yml index b8b67730..9ec6ba36 100755 --- a/src/spiffworkflow_backend/api.yml +++ b/src/spiffworkflow_backend/api.yml @@ -337,7 +337,7 @@ paths: - name: process_status in: query required: false - description: For filtering - not_started, user_input_required, waiting, complete, or erroring + description: For filtering - not_started, user_input_required, waiting, complete, faulted, or suspended schema: type: string # process_instance_list diff --git a/src/spiffworkflow_backend/models/process_instance.py b/src/spiffworkflow_backend/models/process_instance.py index 9666e69e..b9014e9a 100644 --- a/src/spiffworkflow_backend/models/process_instance.py +++ b/src/spiffworkflow_backend/models/process_instance.py @@ -72,7 +72,8 @@ class ProcessInstanceStatus(enum.Enum): user_input_required = "user_input_required" waiting = "waiting" complete = "complete" - erroring = "erroring" + faulted = "faulted" + suspended = "suspended" class ProcessInstanceModel(SpiffworkflowBaseDBModel): @@ -90,7 +91,7 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel): end_in_seconds: int | None = db.Column(db.Integer) # type: ignore updated_at_in_seconds: int = db.Column(db.Integer) # type: ignore created_at_in_seconds: int = db.Column(db.Integer) # type: ignore - status: ProcessInstanceStatus = db.Column(db.Enum(ProcessInstanceStatus)) # type: ignore + status: str = db.Column(db.String()) # type: ignore @property def serialized(self) -> dict[str, int | str | None]: @@ -99,7 +100,7 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel): "id": self.id, "process_model_identifier": self.process_model_identifier, "process_group_identifier": self.process_group_identifier, - "status": self.status.value, + "status": self.status, "bpmn_json": self.bpmn_json, "start_in_seconds": self.start_in_seconds, "end_in_seconds": self.end_in_seconds, @@ -128,7 +129,7 @@ class ProcessInstanceModelSchema(Schema): status = marshmallow.fields.Method('get_status', dump_only=True) def get_status(self, obj): - return obj.status.value + return obj.status class ProcessInstanceApi: diff --git a/src/spiffworkflow_backend/models/process_model.py b/src/spiffworkflow_backend/models/process_model.py index 9d4a1e98..2ba1166a 100644 --- a/src/spiffworkflow_backend/models/process_model.py +++ b/src/spiffworkflow_backend/models/process_model.py @@ -40,7 +40,7 @@ class ProcessModelInfo: display_order: int | None = 0 is_review: bool = False files: list[File] | None = field(default_factory=list[File]) - fault_or_suspend_on_exception: NotificationType = NotificationType.suspend + fault_or_suspend_on_exception: NotificationType = NotificationType.fault.value notification_email_on_exception: list[str] = field(default_factory=list) def __post_init__(self) -> None: diff --git a/src/spiffworkflow_backend/services/process_instance_processor.py b/src/spiffworkflow_backend/services/process_instance_processor.py index bf8b8a68..13747fff 100644 --- a/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/src/spiffworkflow_backend/services/process_instance_processor.py @@ -317,7 +317,7 @@ class ProcessInstanceProcessor: self.process_instance_model.bpmn_json = self.serialize() complete_states = [TaskState.CANCELLED, TaskState.COMPLETED] user_tasks = list(self.get_all_user_tasks()) - self.process_instance_model.status = self.get_status() + self.process_instance_model.status = self.get_status().value self.process_instance_model.total_tasks = len(user_tasks) self.process_instance_model.completed_tasks = sum( 1 for t in user_tasks if t.state in complete_states diff --git a/src/spiffworkflow_backend/services/process_instance_service.py b/src/spiffworkflow_backend/services/process_instance_service.py index d6a4dc24..5c0edd19 100644 --- a/src/spiffworkflow_backend/services/process_instance_service.py +++ b/src/spiffworkflow_backend/services/process_instance_service.py @@ -34,7 +34,7 @@ class ProcessInstanceService: ) -> ProcessInstanceModel: """Get_process_instance_from_spec.""" process_instance_model = ProcessInstanceModel( - status=ProcessInstanceStatus.not_started, + status=ProcessInstanceStatus.not_started.value, process_initiator=user, process_model_identifier=process_model_identifier, process_group_identifier=process_group_identifier, diff --git a/tests/spiffworkflow_backend/integration/test_process_api.py b/tests/spiffworkflow_backend/integration/test_process_api.py index 83b6c0db..105834c8 100644 --- a/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/tests/spiffworkflow_backend/integration/test_process_api.py @@ -670,12 +670,12 @@ def test_process_instance_list_filter( test_process_model_id = "sample" user = find_or_create_user() load_test_spec(test_process_model_id, process_group_id=test_process_group_id) - statuses = ("not_started", "user_input_required", "waiting", "complete", "erroring") + statuses = [status.value for status in ProcessInstanceStatus] # create 5 instances with different status, and different start_in_seconds/end_in_seconds for i in range(5): process_instance = ProcessInstanceModel( - status=ProcessInstanceStatus[statuses[i]], + status=ProcessInstanceStatus[statuses[i]].value, process_initiator=user, process_model_identifier=test_process_model_id, process_group_identifier=test_process_group_id,