代码优化
This commit is contained in:
parent
a8405be6e9
commit
938b8ebf15
|
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import time
|
||||
from datetime import datetime
|
||||
from typing import Optional, Dict, Any, List
|
||||
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])
|
||||
result = self.task_all.check_phone_status(pad_code=data["pad_code"], file_name="test_abc.js")
|
||||
if result:
|
||||
return True
|
||||
print(f"云机:{data['pad_code']}备份完成")
|
||||
return True
|
||||
else:
|
||||
print(f"云机:{data['pad_code']} 300秒备份失败,需要认为干预")
|
||||
else:
|
||||
|
|
@ -99,24 +100,25 @@ class DealAccount:
|
|||
result = await self.db_pool.fetch_all(sql_str, )
|
||||
if result:
|
||||
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")}
|
||||
params = (res_dict["account_id"],)
|
||||
where_conditions = "account_id = %s "
|
||||
result_sql = await self.update_device_status(set_param, where_conditions, params)
|
||||
if result_sql:
|
||||
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 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.async_execute_adb_command(pad_code=data["pad_code"], file_name=res_dict["script_name"])
|
||||
# 需要新增函数
|
||||
return True
|
||||
else:
|
||||
print(f"云机:{data['pad_code']} 300环境还原失败,需要认为干预")
|
||||
restore = self.task_all.restore_system(pad_code=data["pad_code"], backup_name=res_dict["backup_name"])
|
||||
if restore:
|
||||
result_status = self.task_all.check_phone_status(pad_code=data["pad_code"], file_name="test_abc.js")
|
||||
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.async_execute_adb_command(pad_code=data["pad_code"], file_name=res_dict["script_name"])
|
||||
# 需要新增函数
|
||||
return True
|
||||
else:
|
||||
print(f"云机:{data['pad_code']} 300环境还原失败,需要认为干预")
|
||||
|
||||
return False
|
||||
|
||||
|
|
|
|||
4
main.py
4
main.py
|
|
@ -1,6 +1,8 @@
|
|||
import os
|
||||
import time
|
||||
import yaml
|
||||
import uuid
|
||||
import random
|
||||
import asyncio
|
||||
import uvicorn
|
||||
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))
|
||||
restore_result = await account_manager.deal_restore_system(param)
|
||||
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")} 备份还原失败")
|
||||
else:
|
||||
if result:
|
||||
|
|
|
|||
Loading…
Reference in New Issue