leechard / app /models /task_event.py
nenae18's picture
Deploy LeeChard
5d3c2a9 verified
Raw
History Blame Contribute Delete
1.3 kB
"""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: # pragma: no cover
return f"<TaskEvent {self.task_id} {self.old_status}->{self.new_status}>"