代码优化
This commit is contained in:
parent
5a5ba0da43
commit
e4bfd76349
|
|
@ -5,6 +5,9 @@ from datetime import datetime
|
|||
from typing import Optional, Dict, Any, List
|
||||
from public_function.asyn_mysql import AsyncMySQL
|
||||
from public_function.deal_all_task import DealAllTask
|
||||
from public_function.public_func import create_logger
|
||||
|
||||
logger = create_logger("shopee_crawler")
|
||||
|
||||
|
||||
class DealAccount:
|
||||
|
|
@ -73,7 +76,7 @@ class DealAccount:
|
|||
sql_str = f"""select account_id from shoppe_device_record where account_id='{data['account_id']}'"""
|
||||
result = await self.db_pool.fetch_all(sql_str, )
|
||||
if result:
|
||||
print(f"该账号:{data['account_id']} 已经备份过,不需要在备份")
|
||||
logger.info(f"该账号:{data['account_id']} 已经备份过,不需要在备份")
|
||||
return True
|
||||
else:
|
||||
tasks = self.task_all.backup_system([data["pad_code"]], data["pad_code"].lower())
|
||||
|
|
@ -84,12 +87,12 @@ 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:
|
||||
print(f"云机:{data['pad_code']}备份完成")
|
||||
logger.info(f"云机:{data['pad_code']}备份完成")
|
||||
return True
|
||||
else:
|
||||
print(f"云机:{data['pad_code']} 300秒备份失败,需要认为干预")
|
||||
logger.info(f"云机:{data['pad_code']} 300秒备份失败,需要认为干预")
|
||||
else:
|
||||
print(f"实例:{data['pad_code']} 不存在")
|
||||
logger.info(f"实例:{data['pad_code']} 不存在")
|
||||
return False
|
||||
|
||||
async def deal_restore_system(self, data: Dict[str, Any]):
|
||||
|
|
@ -99,7 +102,7 @@ class DealAccount:
|
|||
result = await self.db_pool.fetch_all(sql_str, )
|
||||
if result:
|
||||
res_dict = result[0]
|
||||
print(f"<UNK>{data['account_id']} <UNK>")
|
||||
logger.info(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 "
|
||||
|
|
@ -109,11 +112,11 @@ class DealAccount:
|
|||
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']} 环境还原成功")
|
||||
logger.info(f"云机:{data['pad_code']} 环境还原成功")
|
||||
# 下载执行脚本
|
||||
self.task_all.upload_file_to_phone([data["pad_code"]], file_name=res_dict["script_name"])
|
||||
# 设置代理
|
||||
print(data)
|
||||
logger.info(data)
|
||||
time.sleep(10)
|
||||
self.task_all.set_network_proxy(pad_code=[data["pad_code"]], country=data["country"])
|
||||
# 启动对应脚本
|
||||
|
|
@ -122,9 +125,9 @@ class DealAccount:
|
|||
# 需要新增函数
|
||||
return True
|
||||
else:
|
||||
print(f"云机:{data['pad_code']} 300环境还原失败,需要认为干预")
|
||||
logger.info(f"云机:{data['pad_code']} 300环境还原失败,需要认为干预")
|
||||
else:
|
||||
print("未查询到可用还原数据")
|
||||
logger.info("未查询到可用还原数据")
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
|||
2
main.py
2
main.py
|
|
@ -245,7 +245,7 @@ async def shop_backup(background_tasks: BackgroundTasks, backup_data: BackupItem
|
|||
pad_code
|
||||
"""
|
||||
param = backup_data.model_dump()
|
||||
task_id = f"task_{int(asyncio.get_event_loop().time())}"
|
||||
task_id = f"task_{int(time.time())}"
|
||||
param["task_id"] = task_id # 后续需要对任务状态进行记录使用
|
||||
background_tasks.add_task(deal_shopee_task, param, account_manager)
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in New Issue