Skip to content

Commit

Permalink
models: refactor WorkflowStatus to RunStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
audrium committed Oct 9, 2020
1 parent 1ae4df1 commit fc7a18a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
40 changes: 20 additions & 20 deletions reana_db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
]


Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
User,
UserResource,
Workflow,
WorkflowStatus,
RunStatus,
)


Expand Down Expand Up @@ -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
40 changes: 20 additions & 20 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
UserTokenType,
Workflow,
WorkflowResource,
WorkflowStatus,
RunStatus,
)


Expand Down Expand Up @@ -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],
)
Expand Down

0 comments on commit fc7a18a

Please sign in to comment.