fix: auto-project mainland detect sync
This commit is contained in:
@@ -6,12 +6,32 @@ import time
|
||||
from app.core.config import settings
|
||||
from app.services.debug_event_service import push_debug_event
|
||||
from app.services.detect_job_service import get_active_detect_job_summary, get_detect_queue_health, list_recent_detect_run_events
|
||||
from app.services.sync_record_service import append_detect_result_projection_if_changed
|
||||
from app.services.sync_push_service import pull_detect_task_batch_now, push_runtime_projection_now
|
||||
|
||||
|
||||
logger = logging.getLogger("domaincheck.sync_agent")
|
||||
|
||||
|
||||
def _append_detect_result_projection_snapshot(active_job: dict) -> None:
|
||||
if not active_job:
|
||||
return
|
||||
append_detect_result_projection_if_changed(
|
||||
detect={
|
||||
"active_job": active_job,
|
||||
"progress": {
|
||||
"pending": int(active_job.get("items_pending", 0) or 0),
|
||||
"running": int(active_job.get("items_running", 0) or 0),
|
||||
"completed": int(active_job.get("items_completed", 0) or 0),
|
||||
"blacklisted": int(active_job.get("items_blacklisted", 0) or 0),
|
||||
"failed": int(active_job.get("items_failed", 0) or 0),
|
||||
},
|
||||
"phase_label": str(active_job.get("status") or "").strip(),
|
||||
"phase_detail": f"sync-agent snapshot for {active_job.get('job_code', '')}",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def _emit_structured_tick(
|
||||
*,
|
||||
base_event_type: str,
|
||||
@@ -91,6 +111,9 @@ def main() -> None:
|
||||
)
|
||||
while True:
|
||||
try:
|
||||
active_job = get_active_detect_job_summary(event_limit=10)
|
||||
if active_job:
|
||||
_append_detect_result_projection_snapshot(active_job)
|
||||
ok, message, data = push_runtime_projection_now()
|
||||
logger.info("sync tick: ok=%s message=%s data=%s", ok, message, data)
|
||||
push_debug_event(
|
||||
@@ -112,7 +135,6 @@ def main() -> None:
|
||||
payload={"ok": pull_ok, "data": pull_data},
|
||||
)
|
||||
_emit_structured_tick(base_event_type="task_pull", ok=pull_ok, message=pull_message, data=pull_data)
|
||||
active_job = get_active_detect_job_summary(event_limit=10)
|
||||
if active_job:
|
||||
queue_health = get_detect_queue_health(window_minutes=15)
|
||||
recent_events = list_recent_detect_run_events(limit=8)
|
||||
|
||||
Reference in New Issue
Block a user