fix: 合规审查卡死修复 + 小红书复制格式 + today-only过滤
This commit is contained in:
@@ -3,6 +3,7 @@ from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
import os
|
||||
from pathlib import Path
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent.parent
|
||||
|
||||
@@ -140,6 +141,20 @@ def init_db():
|
||||
except Exception:
|
||||
pass # SQLite 不支持 IF NOT EXISTS,但 create_all 对 SQLite 够用,这里仅为 PostgreSQL 迁移
|
||||
|
||||
# 清理卡死的 running 任务(超过 30 分钟无更新的标记为失败)
|
||||
try:
|
||||
with SessionLocal() as sess:
|
||||
from sqlalchemy import text as sa_text
|
||||
cutoff = datetime.now(timezone.utc) - timedelta(minutes=30)
|
||||
sess.execute(
|
||||
sa_text("UPDATE task_logs SET status='failed', message='系统启动时清理卡死任务', finished_at=now() "
|
||||
"WHERE status='running' AND started_at < :cutoff AND module_id != 'scheduled_task_monitor'"),
|
||||
{"cutoff": cutoff}
|
||||
)
|
||||
sess.commit()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user