| 1234567891011121314151617181920212223242526272829303132333435 |
- import enum
- from sqlalchemy import String, Text
- from sqlalchemy.orm import Mapped, mapped_column
- from app.core.base_model import ModelMixin
- class JobStatusEnum(enum.Enum):
- """执行状态枚举"""
- PENDING = "pending"
- RUNNING = "running"
- SUCCESS = "success"
- FAILED = "failed"
- TIMEOUT = "timeout"
- CANCELLED = "cancelled"
- class JobModel(ModelMixin):
- """
- 任务执行日志表
- """
- __tablename__: str = "task_job"
- __table_args__: dict[str, str] = {"comment": "任务执行日志表"}
- job_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True, comment="任务ID")
- job_name: Mapped[str | None] = mapped_column(String(128), nullable=True, comment="任务名称")
- trigger_type: Mapped[str | None] = mapped_column(String(32), nullable=True, comment="触发方式: cron/interval/date/manual")
- status: Mapped[str] = mapped_column(String(16), nullable=False, default=JobStatusEnum.PENDING.value, comment="执行状态")
- next_run_time: Mapped[str | None] = mapped_column(String(64), nullable=True, comment="下次执行时间")
- job_state: Mapped[str | None] = mapped_column(Text, nullable=True, comment="任务状态信息")
- result: Mapped[str | None] = mapped_column(Text, nullable=True, comment="执行结果")
- error: Mapped[str | None] = mapped_column(Text, nullable=True, comment="错误信息")
|