Commit 0095c18e by baiquan

refactor(shop): 重构任务处理逻辑并优化任务类型判断- 使用 TaskType 枚举替代硬编码的数字,提高代码可读性

- 根据任务类型优化睡眠时间,提高处理效率
- 添加对未知任务类型的处理,增强代码健壮性
parent a5f07d1d
......@@ -138,7 +138,7 @@ def run_sync_shop(task):
async def handle_task(task):
"""处理单个任务,根据类型分发"""
type_ = task.get('type', -1)
if type_ == 1:
if type_ == TaskType.DOUDIAN_SHOP_LOGIN:
# 同步店铺任务 - 使用线程池执行
with concurrent.futures.ThreadPoolExecutor(max_workers=INNER_MAX_WORKERS) as inner_executor:
future = inner_executor.submit(run_sync_shop, task)
......@@ -148,7 +148,7 @@ async def handle_task(task):
logger.error(f"同步店铺任务超时: {task}")
except Exception as e:
logger.error(f"同步店铺任务异常: {e}")
elif type_ == 2:
elif type_ == TaskType.DOUDIAN_UPLOAD_IMAGE_AND_VIDEO:
# 上传图片和视频任务 - 使用线程池执行
with concurrent.futures.ThreadPoolExecutor(max_workers=INNER_MAX_WORKERS) as inner_executor:
future = inner_executor.submit(run_upload_image_and_video, task)
......@@ -228,4 +228,9 @@ if __name__ == '__main__':
sys.exit(0)
while True:
asyncio.run(run(task_type))
time.sleep(10)
if task_type == TaskType.DOUDIAN_SHOP_LOGIN:
time.sleep(10)
elif task_type == TaskType.DOUDIAN_UPLOAD_IMAGE_AND_VIDEO:
time.sleep(1)
else:
time.sleep(5)
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