Skip to content

Commit

Permalink
Fix circulation import error and remove @classmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
jhj0517 committed Dec 7, 2024
1 parent 2df6135 commit 20190e7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
29 changes: 0 additions & 29 deletions backend/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,6 @@ class QueueResponse(BaseModel):
message: str = Field(..., description="Message providing additional information about the task")


class TaskStatusResponse(BaseModel):
identifier: str = Field(..., description="Unique identifier for the queued task that can be used for tracking")
status: TaskStatus = Field(..., description="Current status of the task")
task_type: Optional[TaskType] = Field(
default=None,
description="Type/category of the task"
)
result_type: Optional[ResultType] = Field(
default=ResultType.JSON,
description="Result type whether it's a filepath or JSON"
)
result: Optional[dict] = Field(
default=None,
description="JSON data representing the result of the task"
)
task_params: Optional[dict] = Field(
default=None,
description="Parameters of the task"
)
error: Optional[str] = Field(
default=None,
description="Error message, if any, associated with the task"
)
duration: Optional[float] = Field(
default=None,
description="Duration of the task execution"
)


class Response(BaseModel):
identifier: str
message: str
Expand Down
53 changes: 40 additions & 13 deletions backend/db/task/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
from uuid import uuid4
from datetime import datetime
from sqlalchemy.types import Enum as SQLAlchemyEnum
from typing import Any
from sqlmodel import SQLModel, Field, JSON, Column

from backend.common.models import TaskStatusResponse


class ResultType(str, Enum):
JSON = "json"
Expand Down Expand Up @@ -39,6 +38,36 @@ def __str__(self):
return self.value


class TaskStatusResponse(BaseModel):
"""`TaskStatusResponse` is a wrapper class that hides sensitive information from `Task`"""
identifier: str = Field(..., description="Unique identifier for the queued task that can be used for tracking")
status: TaskStatus = Field(..., description="Current status of the task")
task_type: Optional[TaskType] = Field(
default=None,
description="Type/category of the task"
)
result_type: Optional[ResultType] = Field(
default=ResultType.JSON,
description="Result type whether it's a filepath or JSON"
)
result: Optional[dict] = Field(
default=None,
description="JSON data representing the result of the task"
)
task_params: Optional[dict] = Field(
default=None,
description="Parameters of the task"
)
error: Optional[str] = Field(
default=None,
description="Error message, if any, associated with the task"
)
duration: Optional[float] = Field(
default=None,
description="Duration of the task execution"
)


class Task(SQLModel, table=True):
"""
Table to store tasks information.
Expand Down Expand Up @@ -127,18 +156,16 @@ class Task(SQLModel, table=True):
description="Date and time of last update"
)

@classmethod
def to_status_response(cls) -> "TaskStatusResponse":
"""`TaskStatusResponse` is a wrapper class that hides sensitive information from `Task`"""
def to_response(self) -> "TaskStatusResponse":
return TaskStatusResponse(
identifier=cls.uuid,
status=cls.status,
task_type=cls.task_type,
result_type=cls.result_type,
result=cls.result,
task_params=cls.task_params,
error=cls.error,
duration=cls.duration
identifier=self.uuid,
status=self.status,
task_type=self.task_type,
result_type=self.result_type,
result=self.result,
task_params=self.task_params,
error=self.error,
duration=self.duration
)


Expand Down

0 comments on commit 20190e7

Please sign in to comment.