移除内置数据库备份设计,统一走 Coolify 备份
This commit is contained in:
@@ -38,7 +38,7 @@ from flask import Flask, jsonify, request, render_template, session
|
|||||||
|
|
||||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
|
|
||||||
from db import get_db, init_db, get_user_auth, get_user_display_name, backup_database
|
from db import get_db, init_db, get_user_auth, get_user_display_name
|
||||||
from wechat import request_api
|
from wechat import request_api
|
||||||
from timer import restore_active_timers, start_all_order_checkers, _active_timers
|
from timer import restore_active_timers, start_all_order_checkers, _active_timers
|
||||||
|
|
||||||
@@ -251,10 +251,6 @@ def start_snapshot_scheduler():
|
|||||||
cleanup_old_data(days=HISTORY_RETENTION_DAYS)
|
cleanup_old_data(days=HISTORY_RETENTION_DAYS)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[数据清理] 失败: {e}")
|
print(f"[数据清理] 失败: {e}")
|
||||||
try:
|
|
||||||
backup_database()
|
|
||||||
except Exception as e:
|
|
||||||
print(f"[数据备份] 失败: {e}")
|
|
||||||
t = threading.Thread(target=run, daemon=True)
|
t = threading.Thread(target=run, daemon=True)
|
||||||
t.start()
|
t.start()
|
||||||
print("[数据采集] 车辆位置快照采集已启动")
|
print("[数据采集] 车辆位置快照采集已启动")
|
||||||
@@ -663,11 +659,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# 初始化数据库
|
# 初始化数据库
|
||||||
init_db()
|
init_db()
|
||||||
try:
|
|
||||||
backup_database()
|
|
||||||
print("[数据备份] 启动备份完成")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"[数据备份] 失败: {e}")
|
|
||||||
|
|
||||||
# 恢复未过期的计时器
|
# 恢复未过期的计时器
|
||||||
restore_active_timers()
|
restore_active_timers()
|
||||||
|
|||||||
+1
-2
@@ -13,8 +13,7 @@ timer.start_rental_timer = lambda *a, **k: None # 防止测试期间发出真
|
|||||||
import app as app_module
|
import app as app_module
|
||||||
|
|
||||||
app_module.init_db()
|
app_module.init_db()
|
||||||
app_module.backup_database()
|
print("[smoke] init_db 完成")
|
||||||
print("[smoke] init_db + backup 完成")
|
|
||||||
|
|
||||||
app_module.restore_active_timers()
|
app_module.restore_active_timers()
|
||||||
app_module.start_all_order_checkers()
|
app_module.start_all_order_checkers()
|
||||||
|
|||||||
+55
-56
@@ -1,56 +1,55 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""真实启动冒烟测试: 执行 app.py 的完整启动序列并验证 HTTP 服务可响应。
|
"""真实启动冒烟测试: 执行 app.py 的完整启动序列并验证 HTTP 服务可响应。
|
||||||
唯一差异: start_rental_timer 被置空, 避免测试期间触发真实提醒邮件/自动还车。"""
|
唯一差异: start_rental_timer 被置空, 避免测试期间触发真实提醒邮件/自动还车。"""
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) # 项目根
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) # 项目根
|
||||||
|
|
||||||
import timer
|
import timer
|
||||||
timer.start_rental_timer = lambda *a, **k: None # 防止测试期间发出真实邮件
|
timer.start_rental_timer = lambda *a, **k: None # 防止测试期间发出真实邮件
|
||||||
|
|
||||||
import app as app_module
|
import app as app_module
|
||||||
|
|
||||||
app_module.init_db()
|
app_module.init_db()
|
||||||
app_module.backup_database()
|
print("[smoke] init_db 完成")
|
||||||
print("[smoke] init_db + backup 完成")
|
|
||||||
|
app_module.restore_active_timers()
|
||||||
app_module.restore_active_timers()
|
app_module.start_all_order_checkers()
|
||||||
app_module.start_all_order_checkers()
|
app_module.start_snapshot_scheduler()
|
||||||
app_module.start_snapshot_scheduler()
|
|
||||||
|
PORT = 9987
|
||||||
PORT = 9987
|
t = threading.Thread(
|
||||||
t = threading.Thread(
|
target=lambda: app_module.app.run(host="127.0.0.1", port=PORT, debug=False),
|
||||||
target=lambda: app_module.app.run(host="127.0.0.1", port=PORT, debug=False),
|
daemon=True,
|
||||||
daemon=True,
|
)
|
||||||
)
|
t.start()
|
||||||
t.start()
|
|
||||||
|
# 等待服务就绪
|
||||||
# 等待服务就绪
|
ok = False
|
||||||
ok = False
|
for _ in range(30):
|
||||||
for _ in range(30):
|
time.sleep(0.3)
|
||||||
time.sleep(0.3)
|
try:
|
||||||
try:
|
with urllib.request.urlopen(f"http://127.0.0.1:{PORT}/", timeout=3) as r:
|
||||||
with urllib.request.urlopen(f"http://127.0.0.1:{PORT}/", timeout=3) as r:
|
body = r.read(200)
|
||||||
body = r.read(200)
|
print(f"[smoke] GET / -> {r.status}, body[:60]={body[:60]!r}")
|
||||||
print(f"[smoke] GET / -> {r.status}, body[:60]={body[:60]!r}")
|
ok = r.status == 200
|
||||||
ok = r.status == 200
|
break
|
||||||
break
|
except Exception:
|
||||||
except Exception:
|
continue
|
||||||
continue
|
|
||||||
|
# 再打两个关键接口
|
||||||
# 再打两个关键接口
|
for path in ("/api/config", "/api/history/stats"):
|
||||||
for path in ("/api/config", "/api/history/stats"):
|
try:
|
||||||
try:
|
with urllib.request.urlopen(f"http://127.0.0.1:{PORT}{path}", timeout=5) as r:
|
||||||
with urllib.request.urlopen(f"http://127.0.0.1:{PORT}{path}", timeout=5) as r:
|
print(f"[smoke] GET {path} -> {r.status}")
|
||||||
print(f"[smoke] GET {path} -> {r.status}")
|
except Exception as e:
|
||||||
except Exception as e:
|
print(f"[smoke] GET {path} -> 异常 {e}")
|
||||||
print(f"[smoke] GET {path} -> 异常 {e}")
|
ok = False
|
||||||
ok = False
|
|
||||||
|
import os
|
||||||
import os
|
os._exit(0 if ok else 1)
|
||||||
os._exit(0 if ok else 1)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user