refactor: remove publisher, add auto DB sync, clean backups, update docs

This commit is contained in:
lt
2026-05-01 10:05:50 +08:00
parent 98c6c22a26
commit 601fc5d239
6 changed files with 7 additions and 286 deletions
+6
View File
@@ -30,6 +30,11 @@ def run_creator(topic_id: str = None):
)
if result.returncode != 0:
logger.error(f"Creator failed: {result.stderr}")
if topic_id:
try:
sync_topic_to_db(topic_id)
except Exception as e:
logger.warning(f"Sync after creation failed: {e}")
return {"ok": False, "error": result.stderr}
# 解析日志,找出选择了哪个选题
@@ -42,6 +47,7 @@ def run_creator(topic_id: str = None):
if "选题" in line and "已标记为「待发布」" in line:
# 如: 2026-04-16 ... INFO - 选题 A01 已标记为「待发布」
import re
from .sync import sync_topic_to_db
m = re.search(r'选题\s+([A-Za-z0-9]+)', line)
if m:
topic_id = m.group(1)
-49
View File
@@ -1,49 +0,0 @@
from pathlib import Path
import subprocess
import sys
PROJECT_ROOT = Path(__file__).resolve().parents[4]
def run_publisher(topic_id: str = None):
"""运行发布包生成脚本
Args:
topic_id: 可选,指定单个选题ID
Returns:
dict: 包含 ok, result/error, topic_id 等字段
"""
try:
script_path = PROJECT_ROOT / "scripts" / "publisher.py"
if not script_path.exists():
return {"ok": False, "error": f"Publisher script not found: {script_path}"}
cmd = [sys.executable, str(script_path)]
if topic_id:
cmd.extend(["--topic-id", topic_id])
result = subprocess.run(
cmd,
capture_output=True,
text=True,
cwd=PROJECT_ROOT,
timeout=300 # 5分钟超时
)
if result.returncode == 0:
return {
"ok": True,
"result": result.stdout,
"topic_id": topic_id
}
else:
return {
"ok": False,
"error": result.stderr,
"result": result.stdout,
"topic_id": topic_id
}
except subprocess.TimeoutExpired:
return {"ok": False, "error": "Publisher timed out after 5 minutes", "topic_id": topic_id}
except Exception as e:
return {"ok": False, "error": str(e), "topic_id": topic_id}