Commit 84632006 by baiquan

refactor(service): 优化抖店服务和上传图片视频服务

- 重构了抖店服务中的视频生成逻辑,移除了不必要的重试循环
- 增加了任务执行超时时间,从30秒调整到60秒
- 调整了上传图片视频服务中的超时时间,从85秒增加到110秒
parent 15ccd135
...@@ -146,10 +146,6 @@ def generate_video(task: dict): ...@@ -146,10 +146,6 @@ def generate_video(task: dict):
ua = headers['user-agent'] ua = headers['user-agent']
else: else:
raise Exception('User-Agent not found') raise Exception('User-Agent not found')
retry_count = 0
while True:
if retry_count > 2:
raise Exception('生成视频失败')
a_bogus = generate_a_bogus(params, json_data, ua) a_bogus = generate_a_bogus(params, json_data, ua)
params['a_bogus'] = a_bogus params['a_bogus'] = a_bogus
logger.info("开始生成视频") logger.info("开始生成视频")
...@@ -160,8 +156,7 @@ def generate_video(task: dict): ...@@ -160,8 +156,7 @@ def generate_video(task: dict):
tool_source = response['data']['tool_source'] tool_source = response['data']['tool_source']
result = get_task_result(task_id, headers, tool_source, ua, proxies, cookies) result = get_task_result(task_id, headers, tool_source, ua, proxies, cookies)
if not result: if not result:
retry_count += 1 raise Exception('生成视频失败')
continue
return result return result
def get_task_result(task_id: str, headers: dict, tool_source: str, ua, proxies, cookies): def get_task_result(task_id: str, headers: dict, tool_source: str, ua, proxies, cookies):
...@@ -179,7 +174,7 @@ def get_task_result(task_id: str, headers: dict, tool_source: str, ua, proxies, ...@@ -179,7 +174,7 @@ def get_task_result(task_id: str, headers: dict, tool_source: str, ua, proxies,
url = 'https://fxg.jinritemai.com/product/tproduct/material/imageTextVideo/queryImgOptimizeTask4PC' url = 'https://fxg.jinritemai.com/product/tproduct/material/imageTextVideo/queryImgOptimizeTask4PC'
start_time = time.time() start_time = time.time()
while True: while True:
if time.time() - start_time > 30: if time.time() - start_time > 60:
logger.error('任务执行超时') logger.error('任务执行超时')
return None return None
response = doudian_request("GET", url, proxies, params, headers=headers, cookies=cookies) response = doudian_request("GET", url, proxies, params, headers=headers, cookies=cookies)
......
...@@ -197,8 +197,8 @@ async def uploadImageAndVideo(task: dict = None): ...@@ -197,8 +197,8 @@ async def uploadImageAndVideo(task: dict = None):
error_msg = "" error_msg = ""
# 准备SKU图片上传 # 准备SKU图片上传
sku_image_list = [] sku_image_list = []
# 设置超时时间为85 # 设置超时时间为110
timeout_seconds = 85 timeout_seconds = 110
start_time = time.time() start_time = time.time()
try: try:
for sku in skus: for sku in skus:
......
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