| """task ๊ฐ์ฌ ๋ก๊ทธ โ ์๋ ์ฌ์ฒ๋ฆฌ ๋ฑ ์ด์ ํ์๋ฅผ ๊ธฐ๋ก.""" |
| import uuid |
| from datetime import datetime, timezone |
|
|
| from sqlalchemy import DateTime, Integer, String, Text |
| from sqlalchemy.orm import Mapped, mapped_column |
|
|
| from app.db.base import Base |
|
|
|
|
| def _utcnow() -> datetime: |
| return datetime.now(timezone.utc) |
|
|
|
|
| class TaskEvent(Base): |
| __tablename__ = "task_events" |
|
|
| id: Mapped[str] = mapped_column( |
| String(36), primary_key=True, default=lambda: str(uuid.uuid4()) |
| ) |
| task_id: Mapped[str] = mapped_column(String(36), index=True, nullable=False) |
| actor: Mapped[str] = mapped_column(String(128), nullable=False) |
| reason: Mapped[str | None] = mapped_column(Text, nullable=True) |
| old_status: Mapped[str | None] = mapped_column(String(32), nullable=True) |
| new_status: Mapped[str | None] = mapped_column(String(32), nullable=True) |
| retry_generation: Mapped[int] = mapped_column(Integer, default=0, nullable=False) |
| dispatch_version: Mapped[int] = mapped_column(Integer, default=0, nullable=False) |
| created_at: Mapped[datetime] = mapped_column( |
| DateTime(timezone=True), default=_utcnow, nullable=False |
| ) |
|
|
| def __repr__(self) -> str: |
| return f"<TaskEvent {self.task_id} {self.old_status}->{self.new_status}>" |
|
|