Skip to content

Commit

Permalink
Merge pull request #974 from fractal-analytics-platform/935-review-en…
Browse files Browse the repository at this point in the history
…um-related-behavior

Review use of `Enum`s
  • Loading branch information
tcompa authored Nov 16, 2023
2 parents 79a8988 + 3503a6c commit 0b3268f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Make `ApplyWorkflow.start_timestamp` non-nullable (\#927).
* Remove `"cascade": "all, delete-orphan"` from `Project.job_list` (\#927).
* Add `Workflow.job_list` relation (\#927).
* Do not use `Enum`s as column types (e.g. for `ApplyWorkflow.status`), but only for (de-)serialization (\#974).
* Runner:
* Refresh DB objects within `submit_workflow` (\#927).
* Testing:
Expand Down
2 changes: 1 addition & 1 deletion fractal_server/app/api/v1/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
from ...db import get_db
from ...models import ApplyWorkflow
from ...models import Dataset
from ...models import JobStatusType
from ...models import Resource
from ...runner._common import HISTORY_FILENAME
from ...schemas import DatasetCreate
from ...schemas import DatasetRead
from ...schemas import DatasetStatusRead
from ...schemas import DatasetUpdate
from ...schemas import JobStatusType
from ...schemas import ResourceCreate
from ...schemas import ResourceRead
from ...schemas import ResourceUpdate
Expand Down
2 changes: 1 addition & 1 deletion fractal_server/app/api/v1/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
from ...db import get_db
from ...db import get_sync_db
from ...models import ApplyWorkflow
from ...models import JobStatusType
from ...models import LinkUserProject
from ...models import Project
from ...runner import submit_workflow
from ...runner import validate_workflow_compatibility
from ...runner.common import set_start_and_last_task_index
from ...schemas import ApplyWorkflowCreate
from ...schemas import ApplyWorkflowRead
from ...schemas import JobStatusType
from ...schemas import ProjectCreate
from ...schemas import ProjectRead
from ...schemas import ProjectUpdate
Expand Down
29 changes: 2 additions & 27 deletions fractal_server/app/models/job.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import datetime
from enum import Enum
from typing import Any
from typing import Optional

Expand All @@ -10,34 +9,10 @@
from sqlmodel import SQLModel

from ...utils import get_timestamp
from ..schemas import JobStatusType
from ..schemas.applyworkflow import _ApplyWorkflowBase


class JobStatusType(str, Enum):
"""
Define the job status available
Attributes:
SUBMITTED:
The workflow has been applied but not yet scheduled with an
executor. In this phase, due diligence takes place, such as
creating working directory, assemblying arguments, etc.
RUNNING:
The workflow was scheduled with an executor. Note that it might not
yet be running within the executor, e.g., jobs could still be
pending within a SLURM executor.
DONE:
The workflow was applied successfully
FAILED:
The workflow terminated with an error.
"""

SUBMITTED = "submitted"
RUNNING = "running"
DONE = "done"
FAILED = "failed"


class ApplyWorkflow(_ApplyWorkflowBase, SQLModel, table=True):
"""
Represent a workflow run
Expand Down Expand Up @@ -115,5 +90,5 @@ class Config:
end_timestamp: Optional[datetime] = Field(
default=None, sa_column=Column(DateTime(timezone=True))
)
status: JobStatusType = JobStatusType.SUBMITTED
status: str = JobStatusType.SUBMITTED
log: Optional[str] = None
2 changes: 1 addition & 1 deletion fractal_server/app/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
from ..db import DB
from ..models import ApplyWorkflow
from ..models import Dataset
from ..models import JobStatusType
from ..models import Workflow
from ..models import WorkflowTask
from ..schemas import JobStatusType
from ._local import process_workflow as local_process_workflow
from .common import close_job_logger
from .common import JobExecutionError
Expand Down
1 change: 1 addition & 0 deletions fractal_server/app/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from .applyworkflow import ApplyWorkflowCreate # noqa: F401
from .applyworkflow import ApplyWorkflowRead # noqa: F401
from .applyworkflow import JobStatusType # noqa: F401
from .dataset import DatasetCreate # noqa: F401
from .dataset import DatasetRead # noqa: F401
from .dataset import DatasetStatusRead # noqa: F401
Expand Down
26 changes: 26 additions & 0 deletions fractal_server/app/schemas/applyworkflow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from enum import Enum
from typing import Any
from typing import Optional

Expand All @@ -14,6 +15,31 @@
)


class JobStatusType(str, Enum):
"""
Define the available job statuses
Attributes:
SUBMITTED:
The workflow has been applied but not yet scheduled with an
executor. In this phase, due diligence takes place, such as
creating working directory, assemblying arguments, etc.
RUNNING:
The workflow was scheduled with an executor. Note that it might not
yet be running within the executor, e.g., jobs could still be
pending within a SLURM executor.
DONE:
The workflow was applied successfully
FAILED:
The workflow terminated with an error.
"""

SUBMITTED = "submitted"
RUNNING = "running"
DONE = "done"
FAILED = "failed"


class _ApplyWorkflowBase(BaseModel):
"""
Base class for `ApplyWorkflow`.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_unit_submit_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from fractal_server.app.db import get_sync_db
from fractal_server.app.models import ApplyWorkflow
from fractal_server.app.models import JobStatusType
from fractal_server.app.runner import submit_workflow
from fractal_server.app.schemas import JobStatusType


async def test_success_submit_workflows(
Expand Down

0 comments on commit 0b3268f

Please sign in to comment.