- get_job_page/add/update/delete/status 按新范式改造(get_info 委托 JobRepository) - pause_job/resume_job/run_job_once/reload_all_jobs 去 R 改 BizError/返回数据 - router 取参包 R;修复多行 config 导入被 ast 破坏问题 【验收】flake8 零告警;应用启动;job 分页运行时正常;12 passed Co-Authored-By: Claude <noreply@anthropic.com>
115 lines
3.7 KiB
Python
115 lines
3.7 KiB
Python
"""
|
||
定时任务模型模块
|
||
=============================================================
|
||
|
||
提供定时任务管理的数据模型定义。
|
||
"""
|
||
|
||
from src.common.base_db import BaseDB
|
||
from src.common.base_model import BaseModel
|
||
from config import DB_PREFIX
|
||
from src.core.database import db
|
||
|
||
|
||
# ============================================================
|
||
# 定时任务模型
|
||
# ============================================================
|
||
|
||
|
||
class Job(BaseModel, BaseDB):
|
||
"""
|
||
定时任务模型
|
||
|
||
用于存储定时任务信息。
|
||
|
||
Attributes:
|
||
id: 主键ID(继承自 BaseModel)
|
||
job_name: 任务名称(String(255),必填)
|
||
job_alias: 任务别名(String(255),可选)
|
||
job_group: 任务分组(String(255),可选)
|
||
job_trigger: 任务触发器(String(255),可选)
|
||
status: 任务状态(Integer,0-未发布 1-运行中 2-暂停 3-删除)
|
||
cron_expression: Cron表达式(String(255),可选)
|
||
execute_policy: 执行策略(Integer,1-立即执行 2-执行一次 3-放弃执行)
|
||
is_sync: 是否同步任务(Integer,0-否 1-是)
|
||
url: 任务URL(String(255),可选)
|
||
note: 任务备注(String(255),可选)
|
||
"""
|
||
|
||
# ============================================================
|
||
# 表配置
|
||
# ============================================================
|
||
|
||
__tablename__ = DB_PREFIX + "job"
|
||
|
||
# ============================================================
|
||
# 字段定义
|
||
# ============================================================
|
||
|
||
# 任务名称
|
||
job_name = db.Column(db.String(255), nullable=False, comment="任务名称")
|
||
|
||
# 任务别名
|
||
job_alias = db.Column(db.String(255), nullable=True, comment="任务别名")
|
||
|
||
# 任务分组
|
||
job_group = db.Column(db.String(255), nullable=True, comment="任务分组")
|
||
|
||
# 任务触发器
|
||
job_trigger = db.Column(db.String(255), nullable=True, comment="任务触发器")
|
||
|
||
# 任务状态:0-未发布 1-运行中 2-暂停 3-删除
|
||
status = db.Column(db.Integer, nullable=False, default=0, comment="任务状态:0-未发布 1-运行中 2-暂停 3-删除")
|
||
|
||
# Cron表达式
|
||
cron_expression = db.Column(db.String(255), nullable=True, comment="Cron表达式")
|
||
|
||
# 执行策略:1-立即执行 2-执行一次 3-放弃执行
|
||
execute_policy = db.Column(
|
||
db.Integer, nullable=False, default=1, comment="执行策略:1-立即执行 2-执行一次 3-放弃执行"
|
||
)
|
||
|
||
# 是否同步任务:0-否 1-是
|
||
is_sync = db.Column(db.Integer, nullable=False, default=0, comment="是否同步任务:0-否 1-是")
|
||
|
||
# 任务URL
|
||
url = db.Column(db.String(255), nullable=True, comment="任务URL")
|
||
|
||
# 任务备注
|
||
note = db.Column(db.String(255), nullable=True, comment="任务备注")
|
||
|
||
# ============================================================
|
||
# 常量定义
|
||
# ============================================================
|
||
|
||
class Status:
|
||
"""任务状态常量"""
|
||
|
||
UNPUBLISHED = 0 # 未发布
|
||
RUNNING = 1 # 运行中
|
||
PAUSED = 2 # 暂停
|
||
DELETED = 3 # 删除
|
||
|
||
class ExecutePolicy:
|
||
"""执行策略常量"""
|
||
|
||
EXECUTE_NOW = 1 # 立即执行
|
||
EXECUTE_ONCE = 2 # 执行一次
|
||
ABANDON = 3 # 放弃执行
|
||
|
||
class IsSync:
|
||
"""是否同步任务常量"""
|
||
|
||
ASYNC = 0 # 异步
|
||
SYNC = 1 # 同步
|
||
|
||
# ============================================================
|
||
# 魔法方法
|
||
# ============================================================
|
||
|
||
def __repr__(self):
|
||
return "定时任务:{}".format(self.job_name)
|
||
|
||
def __str__(self):
|
||
return self.__repr__()
|