diff --git a/reana_db/models.py b/reana_db/models.py index 7472dd2..51eee29 100644 --- a/reana_db/models.py +++ b/reana_db/models.py @@ -260,8 +260,8 @@ class UserToken(Base, Timestamp): type_ = Column(Enum(UserTokenType), nullable=False) -class WorkflowStatus(enum.Enum): - """Enumeration of possible workflow statuses.""" +class RunStatus(enum.Enum): + """Enumeration of possible run statuses.""" created = 0 running = 1 @@ -274,21 +274,21 @@ class WorkflowStatus(enum.Enum): ALLOWED_WORKFLOW_STATUS_TRANSITIONS = [ # Creation - (WorkflowStatus.created, WorkflowStatus.deleted), - (WorkflowStatus.created, WorkflowStatus.running), + (RunStatus.created, RunStatus.deleted), + (RunStatus.created, RunStatus.running), # Running - (WorkflowStatus.running, WorkflowStatus.failed), - (WorkflowStatus.running, WorkflowStatus.finished), - (WorkflowStatus.running, WorkflowStatus.stopped), - (WorkflowStatus.running, WorkflowStatus.running), + (RunStatus.running, RunStatus.failed), + (RunStatus.running, RunStatus.finished), + (RunStatus.running, RunStatus.stopped), + (RunStatus.running, RunStatus.running), # Stopped - (WorkflowStatus.stopped, WorkflowStatus.deleted), + (RunStatus.stopped, RunStatus.deleted), # Failed - (WorkflowStatus.failed, WorkflowStatus.deleted), - (WorkflowStatus.failed, WorkflowStatus.running), + (RunStatus.failed, RunStatus.deleted), + (RunStatus.failed, RunStatus.running), # Finished - (WorkflowStatus.finished, WorkflowStatus.deleted), - (WorkflowStatus.finished, WorkflowStatus.running), + (RunStatus.finished, RunStatus.deleted), + (RunStatus.finished, RunStatus.running), ] @@ -336,7 +336,7 @@ class InteractiveSession(Base, Timestamp): name = Column(String(255)) path = Column(Text) # path to access the interactive session status = Column( - Enum(WorkflowStatus), nullable=False, default=WorkflowStatus.created + Enum(RunStatus), nullable=False, default=RunStatus.created ) owner_id = Column(UUIDType, ForeignKey("__reana.user_.id_")) type_ = Column( @@ -362,7 +362,7 @@ class Workflow(Base, Timestamp): id_ = Column(UUIDType, primary_key=True) name = Column(String(255)) - status = Column(Enum(WorkflowStatus), default=WorkflowStatus.created) + status = Column(Enum(RunStatus), default=RunStatus.created) owner_id = Column(UUIDType, ForeignKey("__reana.user_.id_")) reana_specification = Column(JSONType) input_parameters = Column(JSONType) @@ -403,7 +403,7 @@ def __init__( logs="", input_parameters={}, operational_options={}, - status=WorkflowStatus.created, + status=RunStatus.created, git_ref="", git_repo=None, git_provider=None, @@ -536,13 +536,13 @@ def can_transition_to(self, next_status): def workflow_status_change_listener(workflow, new_status, old_status, initiator): """Workflow status change listener.""" if new_status in [ - WorkflowStatus.finished, - WorkflowStatus.failed, + RunStatus.finished, + RunStatus.failed, ]: workflow.run_finished_at = datetime.now() - elif new_status in [WorkflowStatus.stopped]: + elif new_status in [RunStatus.stopped]: workflow.run_stopped_at = datetime.now() - elif new_status in [WorkflowStatus.running]: + elif new_status in [RunStatus.running]: workflow.run_started_at = datetime.now() finished_at = workflow.run_finished_at or workflow.run_stopped_at diff --git a/tests/conftest.py b/tests/conftest.py index c24d842..98c99c3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,7 +23,7 @@ User, UserResource, Workflow, - WorkflowStatus, + RunStatus, ) @@ -62,15 +62,15 @@ def _run_workflow(time_elapsed_seconds=0.5): reana_specification=[], type_="serial", logs="", - status=WorkflowStatus.created, + status=RunStatus.created, ) # start workflow - workflow.status = WorkflowStatus.running + workflow.status = RunStatus.running session.add(workflow) session.commit() # simulate time elapsed sleep(time_elapsed_seconds) - Workflow.update_workflow_status(session, workflow.id_, WorkflowStatus.finished) + Workflow.update_workflow_status(session, workflow.id_, RunStatus.finished) return workflow return _run_workflow diff --git a/tests/test_models.py b/tests/test_models.py index 715c8d0..8dd1fe9 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -21,7 +21,7 @@ UserTokenType, Workflow, WorkflowResource, - WorkflowStatus, + RunStatus, ) @@ -82,25 +82,25 @@ def test_workflow_run_number_assignment(db, session, new_user): @pytest.mark.parametrize( "from_status, to_status, can_transition", [ - (WorkflowStatus.created, WorkflowStatus.failed, False), - (WorkflowStatus.created, WorkflowStatus.finished, False), - (WorkflowStatus.created, WorkflowStatus.stopped, False), - (WorkflowStatus.deleted, WorkflowStatus.created, False), - (WorkflowStatus.deleted, WorkflowStatus.failed, False), - (WorkflowStatus.deleted, WorkflowStatus.finished, False), - (WorkflowStatus.deleted, WorkflowStatus.stopped, False), - (WorkflowStatus.failed, WorkflowStatus.created, False), - (WorkflowStatus.failed, WorkflowStatus.finished, False), - (WorkflowStatus.failed, WorkflowStatus.stopped, False), - (WorkflowStatus.finished, WorkflowStatus.created, False), - (WorkflowStatus.finished, WorkflowStatus.failed, False), - (WorkflowStatus.finished, WorkflowStatus.stopped, False), - (WorkflowStatus.running, WorkflowStatus.created, False), - (WorkflowStatus.running, WorkflowStatus.deleted, False), - (WorkflowStatus.stopped, WorkflowStatus.created, False), - (WorkflowStatus.stopped, WorkflowStatus.failed, False), - (WorkflowStatus.stopped, WorkflowStatus.finished, False), - (WorkflowStatus.stopped, WorkflowStatus.running, False), + (RunStatus.created, RunStatus.failed, False), + (RunStatus.created, RunStatus.finished, False), + (RunStatus.created, RunStatus.stopped, False), + (RunStatus.deleted, RunStatus.created, False), + (RunStatus.deleted, RunStatus.failed, False), + (RunStatus.deleted, RunStatus.finished, False), + (RunStatus.deleted, RunStatus.stopped, False), + (RunStatus.failed, RunStatus.created, False), + (RunStatus.failed, RunStatus.finished, False), + (RunStatus.failed, RunStatus.stopped, False), + (RunStatus.finished, RunStatus.created, False), + (RunStatus.finished, RunStatus.failed, False), + (RunStatus.finished, RunStatus.stopped, False), + (RunStatus.running, RunStatus.created, False), + (RunStatus.running, RunStatus.deleted, False), + (RunStatus.stopped, RunStatus.created, False), + (RunStatus.stopped, RunStatus.failed, False), + (RunStatus.stopped, RunStatus.finished, False), + (RunStatus.stopped, RunStatus.running, False), ] + [tuple + (True,) for tuple in ALLOWED_WORKFLOW_STATUS_TRANSITIONS], )