fix(douyu): unify binding state and scheduler health
This commit is contained in:
@@ -143,6 +143,7 @@ def list_jobs(
|
||||
# 巡检与重登是两个作业,但通过数据库联动:巡检把行标成 invalid,重登作业的
|
||||
# 候选条件正是这个字段。这里把「当前有多少条等着重登」一并返回,页面才能把
|
||||
# 这层上下游关系显示出来,而不是让人以为两个开关互不相干。
|
||||
from ..background_runtime import background_runtime_status
|
||||
from ..database import worker_engine
|
||||
from ..services.automation.jobs.ck_relogin import count_pending_relogin
|
||||
from ..services.binding_poll_scheduler import (
|
||||
@@ -155,9 +156,31 @@ def list_jobs(
|
||||
from ..services.task_runtime import lane_stats
|
||||
|
||||
pending_relogin = count_pending_relogin(db)
|
||||
scheduler_state = scheduler_status()
|
||||
background_runtime = background_runtime_status()
|
||||
background_scheduler = background_runtime.get("scheduler")
|
||||
if (
|
||||
not scheduler_state["running"]
|
||||
and background_runtime["running"]
|
||||
and isinstance(background_scheduler, dict)
|
||||
and background_scheduler.get("running") is True
|
||||
):
|
||||
scheduler_state = {
|
||||
**scheduler_state,
|
||||
"running": True,
|
||||
"process": "background",
|
||||
"pid": background_runtime.get("pid"),
|
||||
"heartbeatAt": background_runtime.get("heartbeatAt"),
|
||||
}
|
||||
else:
|
||||
scheduler_state = {
|
||||
**scheduler_state,
|
||||
"process": "api" if scheduler_state["running"] else "none",
|
||||
"heartbeatAt": background_runtime.get("heartbeatAt"),
|
||||
}
|
||||
|
||||
return {
|
||||
"scheduler": scheduler_status(),
|
||||
"scheduler": scheduler_state,
|
||||
"runtime": {
|
||||
"task_lanes": lane_stats(),
|
||||
"worker_db_pool": getattr(worker_engine.pool, "status", lambda: "")()
|
||||
@@ -166,6 +189,7 @@ def list_jobs(
|
||||
"binding_poll": binding_poll_status(),
|
||||
"payment_poll": payment_poll_status(),
|
||||
"execution_jobs": execution_job_worker_status(),
|
||||
"background_runtime": background_runtime,
|
||||
},
|
||||
"pending_relogin": pending_relogin,
|
||||
"jobs": [
|
||||
|
||||
Reference in New Issue
Block a user