Files
vps-manager/scripts/sync_all_assets.py
T
gouki abd2fa8206 feat(renewal): 提醒前核对平台真实状态,消除手工数据导致的误报
容错策略:核对失败/无可用通道时标记「未核对」并继续按本地数据提醒,
避免因核对链路故障漏掉真正到期的资产;已停止资产仅在 auto_renew=true
时提醒(停止实例不等于停止扣费)。新增 WHMCS 面板只读适配器,
用于 TotHost 这类没有开放 API 的平台。
2026-10-25 23:05:39 +00:00

40 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""定时同步所有已配凭证账号的云端资产(供 systemd timer 调用)
用法:python scripts/sync_all_assets.py
依赖 .env 中的 MASTER_KEY(解密各账号 API 配置)。
排程须早于 vps-renewal-check(09:00):续费提醒读的是本地库的 expiry_date,
若同步在其之后跑,提醒就会用上一天的旧到期日。
"""
import sys
from pathlib import Path
# 确保能导入 app 包(脚本位于 scripts/ 子目录)
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from sqlmodel import Session
from app.database import assets_engine, init_db
from app.services import sync_service
def main() -> int:
init_db()
with Session(assets_engine) as session:
result = sync_service.sync_all_assets(session)
print(
f"[云资产同步] 账号 {result['total']} | 成功 {result['success']} | 失败 {result['failed']} "
f"| 新增 {result['created']} | 更新 {result['updated']} "
f"| 跳过(无凭证) {result['skipped_no_config']} | 跳过(无适配器) {result['skipped_no_adapter']} "
f"| 跳过(面板核对) {result.get('skipped_panel', 0)}"
)
for err in result["errors"]:
print(f" - {err}")
# 有账号同步失败时返回非 0,让 systemd 记为 failed 便于告警
return 1 if result["failed"] else 0
if __name__ == "__main__":
sys.exit(main())