Skip to content

Commit 3ab6821

Browse files
committed
tasks: Add helper for identifying status as final
Signed-off-by: Phoevos Kalemkeris <[email protected]>
1 parent 9d48604 commit 3ab6821

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

cogstack_model_gateway/common/tasks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class Status(str, Enum):
1818
FAILED = "failed"
1919
REQUEUED = "requeued"
2020

21+
def is_final(self) -> bool:
22+
return self in {self.SUCCEEDED, self.FAILED}
23+
2124

2225
class Task(SQLModel, table=True):
2326
uuid: str = Field(default_factory=lambda: str(uuid.uuid4()), primary_key=True)

tests/unit/common/test_tasks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def task_manager(db_manager: Session) -> TaskManager:
2626
return TaskManager(db_manager)
2727

2828

29+
def test_status_enum() -> None:
30+
for status in Status:
31+
assert isinstance(status, Status)
32+
assert isinstance(status.value, str)
33+
assert status.is_final() == (status in {Status.SUCCEEDED, Status.FAILED})
34+
35+
2936
def test_create_task(task_manager: TaskManager) -> None:
3037
"""Test creating a task with different statuses."""
3138
task_uuid = task_manager.create_task(status=Status.PENDING)

0 commit comments

Comments
 (0)