feat(douyu): 整合自动化中心并修复重登队列
This commit is contained in:
@@ -124,10 +124,20 @@ def list_jobs(
|
||||
):
|
||||
"""列出作业配置、最近一次结果与调度器状态。"""
|
||||
ensure_jobs(db)
|
||||
jobs = db.query(AutomationJob).order_by(AutomationJob.key.asc()).all()
|
||||
active_job_keys = set(registered_jobs())
|
||||
jobs = (
|
||||
db.query(AutomationJob)
|
||||
.filter(AutomationJob.key.in_(active_job_keys))
|
||||
.order_by(AutomationJob.key.asc())
|
||||
.all()
|
||||
)
|
||||
latest: dict[str, AutomationRun] = {}
|
||||
for run in (
|
||||
db.query(AutomationRun).order_by(AutomationRun.id.desc()).limit(200).all()
|
||||
db.query(AutomationRun)
|
||||
.filter(AutomationRun.job_key.in_(active_job_keys))
|
||||
.order_by(AutomationRun.id.desc())
|
||||
.limit(200)
|
||||
.all()
|
||||
):
|
||||
latest.setdefault(run.job_key, run)
|
||||
# 巡检与重登是两个作业,但通过数据库联动:巡检把行标成 invalid,重登作业的
|
||||
@@ -390,6 +400,8 @@ def list_runs(
|
||||
query = db.query(AutomationRun)
|
||||
if job_key:
|
||||
query = query.filter(AutomationRun.job_key == job_key)
|
||||
else:
|
||||
query = query.filter(AutomationRun.job_key.in_(set(registered_jobs())))
|
||||
runs = query.order_by(AutomationRun.id.desc()).limit(limit).all()
|
||||
return {"items": [_run_out(run) for run in runs]}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user