TBC/backend/database.py
d-robotics 633a797226 AutoFlow v2.0: 合并 Test (Robogo) + data-loop-automation (D-Cloud) 为统一平台
- 16 个业务模块,856 个测试用例,40 个 E2E 测试
- 单一 React 19 前端 + PlatformSwitcher 二合一切换
- Flask 后端支持 scenario/dcloud_module/dcloud_e2e/dcloud_all 四种任务类型
- E2E 测试面板:API 全链路(8条) + UI 点击(3条) + 分步测试(3个)
- SSE 实时日志流 + 飞书告警 + 定时调度
- 完整还原原 ToB 平台 TestPanel E2E 模块
2026-06-23 11:48:29 +08:00

40 lines
1.1 KiB
Python

import os
import json
DB_FILE = os.path.join(os.path.dirname(__file__), "db.json")
tasks_db = {}
reports_db = {}
def load_db():
global tasks_db, reports_db
if os.path.exists(DB_FILE):
try:
with open(DB_FILE, "r", encoding="utf-8") as f:
data = json.load(f)
tasks_db = data.get("tasks", {})
reports_db = data.get("reports", {})
except Exception as e:
print(f"DB load failed: {e}")
def save_db():
try:
active_once = [
t for t in tasks_db.values()
if t.get("schedule_type", "once") == "once" and not t.get("is_deleted")
]
if len(active_once) > 100:
sorted_tasks = sorted(active_once, key=lambda t: t.get("created_at", ""))
for t in sorted_tasks[:50]:
tid = t.get("id")
if tid:
t["is_deleted"] = True
with open(DB_FILE, "w", encoding="utf-8") as f:
json.dump({"tasks": tasks_db, "reports": reports_db}, f, ensure_ascii=False)
except Exception:
pass
load_db()