Files
baiyue-logistics-chat/scripts/close_active_sessions.py
T
ouyangxq 805675f8db 重构物流客服模块并完善会话接待工作台
- 拆分应用工厂、业务服务与路由,保留原有 HTTP/SSE 和存储入口
- 分离页面资源,重排客服工作台并完善响应式导航、草稿和附件交互
- 整理维护脚本、请求示例和贡献指南,移除启动脚本中的密钥配置
- 上传文件改为仅本地保留,补充隔离的后端与前端回归验证

验证:46 项 Python 测试通过,含 14 个已有子测试;12 个 Node 前端场景通过。
2026-10-29 10:59:29 +08:00

35 lines
1.1 KiB
Python

"""Close all active human sessions; waiting sessions and messages are preserved."""
import argparse
import sqlite3
from contextlib import closing
from pathlib import Path
DEFAULT_DB = Path(__file__).resolve().parents[1] / "history.db"
def close_active_sessions(db_path=None):
database = Path(db_path if db_path is not None else DEFAULT_DB).expanduser().resolve()
with closing(sqlite3.connect(database.as_uri() + "?mode=rw", uri=True)) as connection:
with connection:
count = connection.execute(
"UPDATE human_sessions SET status='closed' WHERE status='active'"
).rowcount
return count
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--db", type=Path, default=DEFAULT_DB, help="Existing SQLite database")
args = parser.parse_args()
try:
count = close_active_sessions(args.db)
except sqlite3.Error as error:
parser.exit(1, f"Database error: {error}\n")
print(f"Closed {count} active session(s).")
if __name__ == "__main__":
main()