Commit 41f806b0 by baiquan

refactor(service): 优化函数参数和登录逻辑

- 在 envList 函数中添加 timeout 参数,增加请求超时控制
- 修改抖店店铺列表获取逻辑,调整每页数量并优化回调处理
- 根据任务类型动态调整线程池大小,提高处理效率
parent f27b3bc5
......@@ -54,12 +54,12 @@ async def openExe():
subprocess.run(command)
async def envList(json_data: dict = None):
async def envList(json_data: dict = None, timeout: int = 120):
"""
环境列表
"""
url = f'/api/v1/env/list'
return await sendRequest('POST', url, json_data)
return await sendRequest('POST', url, json_data, **{'timeout': timeout})
async def exportCookie(json_data: dict = None):
......
......@@ -167,7 +167,7 @@ async def page_login(browser_id, max_retries=3):
# 登录状态检查
if is_logged_in(tab):
# 验证登录结果
for _ in range(20): # 最多等待30秒
for _ in range(20): # 最多等待20秒
if set_auth_token(tab):
cookies = tab.cookies().as_dict()
PHPSESSID = cookies.get('PHPSESSID', '')
......@@ -192,7 +192,7 @@ async def page_login(browser_id, max_retries=3):
raise AppError("多次登录失败")
# 验证登录结果
for _ in range(20): # 最多等待30秒
for _ in range(20): # 最多等待20秒
logger.debug(f"等待登录结果...")
if tab.title == "首页" and set_auth_token(tab):
cookies = tab.cookies().as_dict()
......
......@@ -44,7 +44,7 @@ async def syncShop(task: dict = None):
query_data = {
'containerName': '抖店',
'current': i,
'size': 200,
'size': 100,
}
if browser_default_id:
try:
......@@ -124,8 +124,12 @@ async def syncShop(task: dict = None):
'browser_type': '',
}
})
logger.info(json.dumps(callback_data))
await callback_task(callback_data, TaskType.DOUDIAN_SHOP_LOGIN)
logger.info(callback_data)
res = await callback_task(callback_data, TaskType.DOUDIAN_SHOP_LOGIN)
if res['code'] == 0:
logger.info("任务回调成功")
else:
logger.error(f"{browser_id} --> 任务回调失败")
if browser_default_id:
await closeBrowser(browser_default_id)
return
......@@ -228,10 +232,6 @@ async def run(task_type):
if __name__ == '__main__':
# 外层线程池大小
OUTER_MAX_WORKERS = 5
# 内层线程池大小(每个任务)
INNER_MAX_WORKERS = 3
argv = sys.argv
try:
if len(argv) != 2:
......@@ -243,11 +243,12 @@ if __name__ == '__main__':
logger.error("请传入任务类型(1为店铺登录,2为上传图片与视频)")
sys.exit(0)
while True:
asyncio.run(run(task_type))
if task_type == TaskType.DOUDIAN_SHOP_LOGIN:
# 外层线程池大小
OUTER_MAX_WORKERS = 1
# 内层线程池大小(每个任务)
INNER_MAX_WORKERS = 1
elif task_type == TaskType.DOUDIAN_UPLOAD_IMAGE_AND_VIDEO:
OUTER_MAX_WORKERS = 15
INNER_MAX_WORKERS = 3
asyncio.run(run(task_type))
time.sleep(1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment