dev
This commit is contained in:
27
domain-api/app/services/dashboard.py
Normal file
27
domain-api/app/services/dashboard.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.core.db import get_db
|
||||
from app.services.runtime_status_service import get_runtime_status
|
||||
|
||||
|
||||
def fetch_overview() -> dict:
|
||||
queries = {
|
||||
"domains_total": "select count(*) from domains",
|
||||
"pending_total": "select count(*) from domains where detect_status = 0",
|
||||
"completed_total": "select count(*) from domains where detect_status = 1",
|
||||
"running_total": "select count(*) from domains where detect_status = 2",
|
||||
"blacklist_total": "select count(*) from domains where detect_status = 3",
|
||||
"failed_total": "select count(*) from domains where detect_status = 4",
|
||||
"sensitive_words_total": "select count(*) from sensitive_words",
|
||||
}
|
||||
result: dict[str, int | str] = {}
|
||||
with get_db() as conn:
|
||||
with conn.cursor() as cur:
|
||||
for key, query in queries.items():
|
||||
cur.execute(query)
|
||||
result[key] = cur.fetchone()[0]
|
||||
runtime = get_runtime_status()
|
||||
result["worker_status"] = "online" if runtime["worker"]["running"] else "offline"
|
||||
result["api_status"] = "online"
|
||||
result["worker_mode"] = runtime["worker"]["mode"]
|
||||
return result
|
||||
Reference in New Issue
Block a user