refactor: extract admin business logic to services, introduce job queue, add derived index helpers

- Move DB operations from routes/admin.py to services/admin.py (get_logs_context, query_summary_statuses, retry_failed, delete/reset operations)
- Add services/jobs.py with Job/JobEvent-based async job queue (create_job, run_job, enqueue_job)
- Add services/derived.py with FTS5 reindex and paper index deletion helpers
- Refactor scheduler to use job queue instead of direct pipeline calls
- Add heartbeat_at/expires_at to TaskLock for lock health tracking
- Remove DESIGN_REVIEW.md
- Update tests: remove redundant integration tests, add unit tests for new services
This commit is contained in:
2026-06-13 18:31:43 +08:00
parent 21f16e6756
commit 743d69efd0
20 changed files with 1391 additions and 1063 deletions
+16
View File
@@ -76,10 +76,26 @@ def _migrate(engine) -> None:
"crawl_logs": [
("details_json", "TEXT"),
],
"task_locks": [
("heartbeat_at", "DATETIME"),
("expires_at", "DATETIME"),
],
"jobs": [
("heartbeat_at", "DATETIME"),
],
}
with engine.connect() as conn:
for table, columns in _MIGRATIONS.items():
table_exists = conn.execute(
text(
"SELECT name FROM sqlite_master "
"WHERE type IN ('table', 'virtual table') AND name = :name"
),
{"name": table},
).fetchone()
if not table_exists:
continue
# 获取已有列名
existing = {
row[1] for row in conn.execute(text(f"PRAGMA table_info({table})"))