from __future__ import annotations from datetime import UTC, datetime from sqlalchemy import DateTime, String, Text from sqlalchemy.orm import Mapped, mapped_column from deerflow.persistence.base import Base class ScheduledTaskRunRow(Base): __tablename__ = "scheduled_task_runs" id: Mapped[str] = mapped_column(String(64), primary_key=True) task_id: Mapped[str] = mapped_column(String(64), index=True) thread_id: Mapped[str] = mapped_column(String(64), index=True) run_id: Mapped[str | None] = mapped_column(String(64), nullable=True) scheduled_for: Mapped[datetime] = mapped_column(DateTime(timezone=True)) trigger: Mapped[str] = mapped_column(String(16)) status: Mapped[str] = mapped_column(String(16), index=True) error: Mapped[str | None] = mapped_column(Text, nullable=True) started_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True) finished_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(UTC))