代码优化

This commit is contained in:
liujianjiang 2026-01-08 15:31:24 +08:00
parent a8405be6e9
commit 938b8ebf15
2 changed files with 19 additions and 15 deletions

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import time
from datetime import datetime from datetime import datetime
from typing import Optional, Dict, Any, List from typing import Optional, Dict, Any, List
from public_function.asyn_mysql import AsyncMySQL from public_function.asyn_mysql import AsyncMySQL
@ -84,8 +85,8 @@ class DealAccount:
await self.db_pool.insert_many(table="shoppe_device_record", data=[payload]) await self.db_pool.insert_many(table="shoppe_device_record", data=[payload])
result = self.task_all.check_phone_status(pad_code=data["pad_code"], file_name="test_abc.js") result = self.task_all.check_phone_status(pad_code=data["pad_code"], file_name="test_abc.js")
if result: if result:
return True
print(f"云机:{data['pad_code']}备份完成") print(f"云机:{data['pad_code']}备份完成")
return True
else: else:
print(f"云机:{data['pad_code']} 300秒备份失败需要认为干预") print(f"云机:{data['pad_code']} 300秒备份失败需要认为干预")
else: else:
@ -99,24 +100,25 @@ class DealAccount:
result = await self.db_pool.fetch_all(sql_str, ) result = await self.db_pool.fetch_all(sql_str, )
if result: if result:
res_dict = result[0] res_dict = result[0]
print(f"<UNK>{params['account_id']} <UNK>") print(f"<UNK>{data['account_id']} <UNK>")
set_param = {"status": 2, "update_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S")} set_param = {"status": 2, "update_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
params = (res_dict["account_id"],) params = (res_dict["account_id"],)
where_conditions = "account_id = %s " where_conditions = "account_id = %s "
result_sql = await self.update_device_status(set_param, where_conditions, params) result_sql = await self.update_device_status(set_param, where_conditions, params)
if result_sql: if result_sql:
self.task_all.restore_system(pad_code=data["pad_code"], backup_name=res_dict["backup_name"]) restore = self.task_all.restore_system(pad_code=data["pad_code"], backup_name=res_dict["backup_name"])
result_status = self.task_all.check_phone_status(pad_code=data["pad_code"], file_name="test_abc.js") if restore:
if result_status: result_status = self.task_all.check_phone_status(pad_code=data["pad_code"], file_name="test_abc.js")
print(f"云机:{data['pad_code']} 环境还原成功") if result_status:
# 下载执行脚本 print(f"云机:{data['pad_code']} 环境还原成功")
self.task_all.upload_file_to_phone([data["pad_code"]], file_name=res_dict["script_name"]) # 下载执行脚本
# 启动对应脚本 self.task_all.upload_file_to_phone([data["pad_code"]], file_name=res_dict["script_name"])
self.task_all.async_execute_adb_command(pad_code=data["pad_code"], file_name=res_dict["script_name"]) # 启动对应脚本
# 需要新增函数 self.task_all.async_execute_adb_command(pad_code=data["pad_code"], file_name=res_dict["script_name"])
return True # 需要新增函数
else: return True
print(f"云机:{data['pad_code']} 300环境还原失败需要认为干预") else:
print(f"云机:{data['pad_code']} 300环境还原失败需要认为干预")
return False return False

View File

@ -1,6 +1,8 @@
import os import os
import time
import yaml import yaml
import uuid import uuid
import random
import asyncio import asyncio
import uvicorn import uvicorn
from pathlib import Path from pathlib import Path
@ -225,7 +227,7 @@ async def shop_backup(backup_data: BackupItem, account_manager: Any = Depends(ge
time.sleep(random.randint(1, 10)) time.sleep(random.randint(1, 10))
restore_result = await account_manager.deal_restore_system(param) restore_result = await account_manager.deal_restore_system(param)
if restore_result and result: if restore_result and result:
return {"code": 200, "message": f"任务:{params.get("pad_code")} 备份还原成功"} return {"code": 200, "message": f"任务:{param.get("pad_code")} 备份还原成功"}
raise HTTPException(status_code=404, detail=f"云机:{param.get("pad_code")} 备份还原失败") raise HTTPException(status_code=404, detail=f"云机:{param.get("pad_code")} 备份还原失败")
else: else:
if result: if result: