model.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import enum
  2. from sqlalchemy import String, Text
  3. from sqlalchemy.orm import Mapped, mapped_column
  4. from app.core.base_model import ModelMixin
  5. class JobStatusEnum(enum.Enum):
  6. """执行状态枚举"""
  7. PENDING = "pending"
  8. RUNNING = "running"
  9. SUCCESS = "success"
  10. FAILED = "failed"
  11. TIMEOUT = "timeout"
  12. CANCELLED = "cancelled"
  13. class JobModel(ModelMixin):
  14. """
  15. 任务执行日志表
  16. """
  17. __tablename__: str = "task_job"
  18. __table_args__: dict[str, str] = {"comment": "任务执行日志表"}
  19. job_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True, comment="任务ID")
  20. job_name: Mapped[str | None] = mapped_column(String(128), nullable=True, comment="任务名称")
  21. trigger_type: Mapped[str | None] = mapped_column(String(32), nullable=True, comment="触发方式: cron/interval/date/manual")
  22. status: Mapped[str] = mapped_column(String(16), nullable=False, default=JobStatusEnum.PENDING.value, comment="执行状态")
  23. next_run_time: Mapped[str | None] = mapped_column(String(64), nullable=True, comment="下次执行时间")
  24. job_state: Mapped[str | None] = mapped_column(Text, nullable=True, comment="任务状态信息")
  25. result: Mapped[str | None] = mapped_column(Text, nullable=True, comment="执行结果")
  26. error: Mapped[str | None] = mapped_column(Text, nullable=True, comment="错误信息")