|
|
|
@ -33,7 +33,7 @@ def main(pid,orderId,styleNumber): |
|
|
|
print("弹出版本选择按钮已成功点击") |
|
|
|
print("弹出版本选择按钮已成功点击") |
|
|
|
time.sleep(3) |
|
|
|
time.sleep(3) |
|
|
|
# 使用XPath定位包含特定文本的div元素 |
|
|
|
# 使用XPath定位包含特定文本的div元素 |
|
|
|
target_text = "深度图批处理" |
|
|
|
target_text = "3.小鱼AI(灰度图)图片浮雕流程-V3" |
|
|
|
button = WebDriverWait(driver, 10).until( |
|
|
|
button = WebDriverWait(driver, 10).until( |
|
|
|
EC.element_to_be_clickable((By.XPATH, f'//div[contains(text(), "{target_text}")]')) |
|
|
|
EC.element_to_be_clickable((By.XPATH, f'//div[contains(text(), "{target_text}")]')) |
|
|
|
) |
|
|
|
) |
|
|
|
@ -177,7 +177,7 @@ if __name__ == '__main__': |
|
|
|
orderId = 0 |
|
|
|
orderId = 0 |
|
|
|
styleNumber = 0 |
|
|
|
styleNumber = 0 |
|
|
|
downloadPath = "D:\downloadPhotos" |
|
|
|
downloadPath = "D:\downloadPhotos" |
|
|
|
inputFolder = "c:\deep" #"C:\StableDiffusion_xiaoyu_V3\ComfyUI-aki-v1.6-XY\ComfyUI\input" |
|
|
|
inputFolder = "C:\StableDiffusion_xiaoyu_V3\ComfyUI-aki-v1.6-XY\ComfyUI\input" #"c:\deep" #"C:\StableDiffusion_xiaoyu_V3\ComfyUI-aki-v1.6-XY\ComfyUI\input" |
|
|
|
outputFolder = "C:\StableDiffusion_xiaoyu_V3\ComfyUI-aki-v1.6-XY\ComfyUI\output" |
|
|
|
outputFolder = "C:\StableDiffusion_xiaoyu_V3\ComfyUI-aki-v1.6-XY\ComfyUI\output" |
|
|
|
jsonFilePath = "C:\StableDiffusion_xiaoyu_V3\ComfyUI-aki-v1.6-XY\ComfyUI\pysssss-workflows" |
|
|
|
jsonFilePath = "C:\StableDiffusion_xiaoyu_V3\ComfyUI-aki-v1.6-XY\ComfyUI\pysssss-workflows" |
|
|
|
# 设置浏览器驱动路径(以Chrome为例) |
|
|
|
# 设置浏览器驱动路径(以Chrome为例) |
|
|
|
@ -232,7 +232,8 @@ if __name__ == '__main__': |
|
|
|
print(f"Redis数据格式错误,缺少必要字段: {info}") |
|
|
|
print(f"Redis数据格式错误,缺少必要字段: {info}") |
|
|
|
utils.notify(f"Redis数据格式错误,缺少必要字段: {info}") |
|
|
|
utils.notify(f"Redis数据格式错误,缺少必要字段: {info}") |
|
|
|
continue |
|
|
|
continue |
|
|
|
|
|
|
|
print(info) |
|
|
|
|
|
|
|
exit |
|
|
|
pid = int(info['pid']) |
|
|
|
pid = int(info['pid']) |
|
|
|
orderId = int(info['order_id']) |
|
|
|
orderId = int(info['order_id']) |
|
|
|
styleNumber = int(info['style_number']) |
|
|
|
styleNumber = int(info['style_number']) |
|
|
|
@ -265,3 +266,361 @@ if __name__ == '__main__': |
|
|
|
r = utils.create_redis_connection() |
|
|
|
r = utils.create_redis_connection() |
|
|
|
continue |
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# from selenium import webdriver |
|
|
|
|
|
|
|
# from selenium.webdriver.common.by import By |
|
|
|
|
|
|
|
# from selenium.webdriver.common.keys import Keys |
|
|
|
|
|
|
|
# from selenium.webdriver.chrome.service import Service |
|
|
|
|
|
|
|
# from selenium.webdriver.support.ui import WebDriverWait |
|
|
|
|
|
|
|
# from selenium.webdriver.support import expected_conditions as EC |
|
|
|
|
|
|
|
# import time |
|
|
|
|
|
|
|
# import os |
|
|
|
|
|
|
|
# import sys |
|
|
|
|
|
|
|
# import oss2 |
|
|
|
|
|
|
|
# import json |
|
|
|
|
|
|
|
# import shutil |
|
|
|
|
|
|
|
# import traceback |
|
|
|
|
|
|
|
# import datetime |
|
|
|
|
|
|
|
# from util import utils |
|
|
|
|
|
|
|
# import requests |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # ===================== 核心修复:Chrome配置 ===================== |
|
|
|
|
|
|
|
# def init_chrome_driver(driver_path, chrome_binary_path=None): |
|
|
|
|
|
|
|
# """初始化Chrome驱动,解决找不到Chrome二进制文件问题""" |
|
|
|
|
|
|
|
# from selenium.webdriver.chrome.options import Options |
|
|
|
|
|
|
|
# chrome_options = Options() |
|
|
|
|
|
|
|
# # 1. 指定Chrome二进制文件路径(关键修复) |
|
|
|
|
|
|
|
# if chrome_binary_path: |
|
|
|
|
|
|
|
# chrome_options.binary_location = chrome_binary_path |
|
|
|
|
|
|
|
# # 2. 添加通用优化参数 |
|
|
|
|
|
|
|
# chrome_options.add_argument("--no-sandbox") # 解决沙箱问题 |
|
|
|
|
|
|
|
# chrome_options.add_argument("--disable-dev-shm-usage") # 解决内存不足 |
|
|
|
|
|
|
|
# chrome_options.add_argument("--disable-gpu") # 禁用GPU加速(兼容老系统) |
|
|
|
|
|
|
|
# chrome_options.add_argument("--window-size=1920,1080") # 设置窗口大小 |
|
|
|
|
|
|
|
# chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"]) # 屏蔽无用日志 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 3. 初始化驱动 |
|
|
|
|
|
|
|
# try: |
|
|
|
|
|
|
|
# service = Service(executable_path=driver_path) |
|
|
|
|
|
|
|
# driver = webdriver.Chrome(service=service, options=chrome_options) |
|
|
|
|
|
|
|
# driver.set_page_load_timeout(60) # 设置页面加载超时 |
|
|
|
|
|
|
|
# return driver |
|
|
|
|
|
|
|
# except Exception as e: |
|
|
|
|
|
|
|
# raise Exception(f"Chrome驱动初始化失败:{str(e)}\n堆栈信息:{traceback.format_exc()}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # ===================== 原有业务函数修改 ===================== |
|
|
|
|
|
|
|
# def main(pid, orderId, styleNumber): |
|
|
|
|
|
|
|
# driver = None |
|
|
|
|
|
|
|
# try: |
|
|
|
|
|
|
|
# # 进行一些初始化的处理 |
|
|
|
|
|
|
|
# flag = init(pid, orderId, styleNumber) |
|
|
|
|
|
|
|
# if flag == False: |
|
|
|
|
|
|
|
# err_msg = f"初始化步骤失败 pid:{pid} orderId:{orderId} styleNumber:{styleNumber}" |
|
|
|
|
|
|
|
# print(err_msg) |
|
|
|
|
|
|
|
# utils.notify(err_msg) |
|
|
|
|
|
|
|
# return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 初始化浏览器(修复核心:指定Chrome二进制路径) |
|
|
|
|
|
|
|
# chrome_binary_path = r"C:\Program Files\Google\Chrome\Application\chrome.exe" # 根据实际路径修改 |
|
|
|
|
|
|
|
# driver = init_chrome_driver(driver_path, chrome_binary_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 打开目标网页 |
|
|
|
|
|
|
|
# driver.get('http://127.0.0.1:8188') # 替换为你的目标网页地址 |
|
|
|
|
|
|
|
# # 等待页面加载完成 |
|
|
|
|
|
|
|
# time.sleep(5) # 等待2秒,确保页面加载完成 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 定位按钮并点击 |
|
|
|
|
|
|
|
# # 1. 点击弹出版本选择按钮 |
|
|
|
|
|
|
|
# button = WebDriverWait(driver, 10).until( |
|
|
|
|
|
|
|
# EC.element_to_be_clickable((By.CSS_SELECTOR, '#comfy-load-button .pysssss-workflow-arrow')) |
|
|
|
|
|
|
|
# ) |
|
|
|
|
|
|
|
# button.click() |
|
|
|
|
|
|
|
# print("弹出版本选择按钮已成功点击") |
|
|
|
|
|
|
|
# time.sleep(3) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 2. 点击"深度图批处理" |
|
|
|
|
|
|
|
# target_text = "深度图批处理" |
|
|
|
|
|
|
|
# button = WebDriverWait(driver, 10).until( |
|
|
|
|
|
|
|
# EC.element_to_be_clickable((By.XPATH, f'//div[contains(text(), "{target_text}")]')) |
|
|
|
|
|
|
|
# ) |
|
|
|
|
|
|
|
# button.click() |
|
|
|
|
|
|
|
# print("选择版本按钮已成功点击") |
|
|
|
|
|
|
|
# time.sleep(3) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 3. 点击"Extra options" |
|
|
|
|
|
|
|
# target_text = "Extra options" |
|
|
|
|
|
|
|
# button = WebDriverWait(driver, 10).until( |
|
|
|
|
|
|
|
# EC.element_to_be_clickable((By.XPATH, f'//label[contains(text(), "{target_text}")]')) |
|
|
|
|
|
|
|
# ) |
|
|
|
|
|
|
|
# button.click() |
|
|
|
|
|
|
|
# time.sleep(5) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 4. 点击队列按钮 |
|
|
|
|
|
|
|
# button = WebDriverWait(driver, 10).until( |
|
|
|
|
|
|
|
# EC.element_to_be_clickable((By.ID, 'queue-button')) |
|
|
|
|
|
|
|
# ) |
|
|
|
|
|
|
|
# button.click() |
|
|
|
|
|
|
|
# print("队列按钮点击成功") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 获取当前时间戳 |
|
|
|
|
|
|
|
# timestamp = int(time.time()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 检测是否完成数据,一个死循环 |
|
|
|
|
|
|
|
# while True: |
|
|
|
|
|
|
|
# boolV = checkIsFinish(driver, pid, orderId, styleNumber) |
|
|
|
|
|
|
|
# if boolV: |
|
|
|
|
|
|
|
# break |
|
|
|
|
|
|
|
# else: |
|
|
|
|
|
|
|
# # 计算时间戳是否超过5分钟了 |
|
|
|
|
|
|
|
# now = int(time.time()) |
|
|
|
|
|
|
|
# if now - timestamp >= 300: |
|
|
|
|
|
|
|
# err_msg = f"pid:{pid} orderId:{orderId} 超过5分钟,任务还没结束,强行停止执行下一个任务" |
|
|
|
|
|
|
|
# print(err_msg) |
|
|
|
|
|
|
|
# utils.notify(err_msg) |
|
|
|
|
|
|
|
# break |
|
|
|
|
|
|
|
# time.sleep(5) |
|
|
|
|
|
|
|
# continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# except Exception as e: |
|
|
|
|
|
|
|
# err_msg = f"pid:{pid} orderId:{orderId} styleNumber:{styleNumber} 执行错误:{str(e)}\n堆栈信息:{traceback.format_exc()}" |
|
|
|
|
|
|
|
# print(err_msg) |
|
|
|
|
|
|
|
# utils.notify(err_msg) |
|
|
|
|
|
|
|
# finally: |
|
|
|
|
|
|
|
# # 确保浏览器关闭 |
|
|
|
|
|
|
|
# if driver: |
|
|
|
|
|
|
|
# try: |
|
|
|
|
|
|
|
# driver.quit() |
|
|
|
|
|
|
|
# except: |
|
|
|
|
|
|
|
# pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def down_obj_from_oss(fileName, pid, styleNumber): |
|
|
|
|
|
|
|
# """从OSS下载文件""" |
|
|
|
|
|
|
|
# path = os.path.join(inputFolder, fileName) |
|
|
|
|
|
|
|
# # 根据前缀获取文件列表 |
|
|
|
|
|
|
|
# prefix = f'photos/{pid}/cartoon/cartoon_image' |
|
|
|
|
|
|
|
# filelist = oss2.ObjectIteratorV2(utils.oss(), prefix=prefix) |
|
|
|
|
|
|
|
# print(f"filelist:{filelist} prefix{prefix}") |
|
|
|
|
|
|
|
# isDownload = False |
|
|
|
|
|
|
|
# for file in filelist: |
|
|
|
|
|
|
|
# if file and hasattr(file, 'key') and f"{styleNumber}.png" in file.key: |
|
|
|
|
|
|
|
# utils.oss().get_object_to_file(file.key, path) |
|
|
|
|
|
|
|
# isDownload = True |
|
|
|
|
|
|
|
# print(f"pid:{pid} styleNumber:{styleNumber} 文件下载成功") |
|
|
|
|
|
|
|
# break |
|
|
|
|
|
|
|
# return isDownload |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def init(pid, orderId, styleNumber): |
|
|
|
|
|
|
|
# """初始化:清空文件夹、下载OSS文件、修改配置文件""" |
|
|
|
|
|
|
|
# try: |
|
|
|
|
|
|
|
# # 清除输入输出里的一些文件 |
|
|
|
|
|
|
|
# clearFolder(outputFolder) |
|
|
|
|
|
|
|
# clearFolder(inputFolder) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 下载oss的文件到指定目录 |
|
|
|
|
|
|
|
# imageName = f"{pid}_{orderId}_{styleNumber}.png" |
|
|
|
|
|
|
|
# downloadRes = down_obj_from_oss(imageName, pid, styleNumber) |
|
|
|
|
|
|
|
# if downloadRes == False: |
|
|
|
|
|
|
|
# print(f"pid:{pid} styleNumber:{styleNumber} OSS文件下载失败") |
|
|
|
|
|
|
|
# return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 修改配置文件:替换LoadImage的inputs[0]的value |
|
|
|
|
|
|
|
# json_file = "3.小鱼AI(灰度图)图片浮雕流程-V3.json" |
|
|
|
|
|
|
|
# json_origin_path = os.path.join(jsonFilePath, json_file) # 修正路径拼接 |
|
|
|
|
|
|
|
# with open(json_origin_path, 'r', encoding='utf-8') as f: |
|
|
|
|
|
|
|
# data = json.load(f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 遍历节点修改值 |
|
|
|
|
|
|
|
# for item in data.get('nodes', []): |
|
|
|
|
|
|
|
# if item.get('id') == 277: |
|
|
|
|
|
|
|
# if len(item.get('widgets_values', [])) > 0: |
|
|
|
|
|
|
|
# item['widgets_values'][0] = imageName |
|
|
|
|
|
|
|
# else: |
|
|
|
|
|
|
|
# print(f"pid:{pid} 节点277的widgets_values为空,无法修改") |
|
|
|
|
|
|
|
# return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 写入修改后的配置文件 |
|
|
|
|
|
|
|
# with open(json_origin_path, 'w', encoding='utf-8') as f: |
|
|
|
|
|
|
|
# json.dump(data, f, ensure_ascii=False, indent=4) |
|
|
|
|
|
|
|
# print(f"pid:{pid} orderId:{orderId} styleNumber:{styleNumber} 配置文件修改成功") |
|
|
|
|
|
|
|
# return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# except Exception as e: |
|
|
|
|
|
|
|
# print(f"初始化失败:{str(e)}") |
|
|
|
|
|
|
|
# utils.notify(f"pid:{pid} orderId:{orderId} 初始化失败:{str(e)}") |
|
|
|
|
|
|
|
# return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def checkIsFinish(driver, pid, orderId, styleNumber): |
|
|
|
|
|
|
|
# """检测任务是否完成:检查输出文件夹、上传OSS""" |
|
|
|
|
|
|
|
# try: |
|
|
|
|
|
|
|
# folder = outputFolder |
|
|
|
|
|
|
|
# # 检查文件夹是否存在 |
|
|
|
|
|
|
|
# if not os.path.exists(folder): |
|
|
|
|
|
|
|
# print(f"输出文件夹不存在:{folder}") |
|
|
|
|
|
|
|
# return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# file_list = os.listdir(folder) |
|
|
|
|
|
|
|
# fileLength = len(file_list) |
|
|
|
|
|
|
|
# uploadCounts = 0 |
|
|
|
|
|
|
|
# files = "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if fileLength == 2: |
|
|
|
|
|
|
|
# # 上传文件到指定的目录 |
|
|
|
|
|
|
|
# for file in file_list: |
|
|
|
|
|
|
|
# files += file + "," |
|
|
|
|
|
|
|
# file_path = os.path.join(folder, file) |
|
|
|
|
|
|
|
# if not os.path.exists(file_path): |
|
|
|
|
|
|
|
# continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 上传TIFF文件 |
|
|
|
|
|
|
|
# if "tiff" in file.lower(): # 忽略大小写 |
|
|
|
|
|
|
|
# ossPath = f"photos/{pid}/cartoon_deep/{styleNumber}/{styleNumber}.tiff" |
|
|
|
|
|
|
|
# time.sleep(5) |
|
|
|
|
|
|
|
# utils.oss().put_object_from_file(ossPath, file_path) |
|
|
|
|
|
|
|
# uploadCounts += 1 |
|
|
|
|
|
|
|
# # 上传PNG文件 |
|
|
|
|
|
|
|
# elif "png" in file.lower(): |
|
|
|
|
|
|
|
# ossPath = f"photos/{pid}/cartoon_deep/{styleNumber}/{styleNumber}.png" |
|
|
|
|
|
|
|
# time.sleep(5) |
|
|
|
|
|
|
|
# utils.oss().put_object_from_file(ossPath, file_path) |
|
|
|
|
|
|
|
# uploadCounts += 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if uploadCounts == 2: |
|
|
|
|
|
|
|
# success_msg = f"pid={pid},orderid={orderId},style_number:{styleNumber} 任务处理完成,深度图已上传到OSS" |
|
|
|
|
|
|
|
# print(success_msg) |
|
|
|
|
|
|
|
# # 推入到队列中 |
|
|
|
|
|
|
|
# r = utils.create_redis_connection() |
|
|
|
|
|
|
|
# if pid > 1000: |
|
|
|
|
|
|
|
# r.lpush('model:badge_cartoon_build', |
|
|
|
|
|
|
|
# json.dumps({'pid': pid, 'order_id': orderId, 'style_number': styleNumber})) |
|
|
|
|
|
|
|
# return True |
|
|
|
|
|
|
|
# else: |
|
|
|
|
|
|
|
# err_msg = f"pid={pid},orderid={orderId},style_number:{styleNumber} 任务处理失败,当前文件数据为{files},仅上传{uploadCounts}个文件" |
|
|
|
|
|
|
|
# print(err_msg) |
|
|
|
|
|
|
|
# utils.notify(err_msg) |
|
|
|
|
|
|
|
# return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# except Exception as e: |
|
|
|
|
|
|
|
# err_msg = f"检测任务完成状态失败:{str(e)}" |
|
|
|
|
|
|
|
# print(err_msg) |
|
|
|
|
|
|
|
# utils.notify(err_msg) |
|
|
|
|
|
|
|
# return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def clearFolder(folder): |
|
|
|
|
|
|
|
# """清除指定文件夹下的所有文件(增强容错)""" |
|
|
|
|
|
|
|
# if not os.path.exists(folder): |
|
|
|
|
|
|
|
# os.makedirs(folder) |
|
|
|
|
|
|
|
# return |
|
|
|
|
|
|
|
# for file in os.listdir(folder): |
|
|
|
|
|
|
|
# file_path = os.path.join(folder, file) |
|
|
|
|
|
|
|
# try: |
|
|
|
|
|
|
|
# if os.path.isdir(file_path): |
|
|
|
|
|
|
|
# shutil.rmtree(file_path) |
|
|
|
|
|
|
|
# else: |
|
|
|
|
|
|
|
# os.remove(file_path) |
|
|
|
|
|
|
|
# except Exception as e: |
|
|
|
|
|
|
|
# print(f"删除文件/文件夹失败 {file_path}:{str(e)}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def checkInputFolder(): |
|
|
|
|
|
|
|
# """检测输入目录里是否有输入的文件存在""" |
|
|
|
|
|
|
|
# folder = inputFolder |
|
|
|
|
|
|
|
# if not os.path.exists(folder): |
|
|
|
|
|
|
|
# return False |
|
|
|
|
|
|
|
# fileLength = os.listdir(folder) |
|
|
|
|
|
|
|
# return len(fileLength) == 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # ===================== 主程序入口修改 ===================== |
|
|
|
|
|
|
|
# if __name__ == '__main__': |
|
|
|
|
|
|
|
# # 全局变量定义(修正路径格式,使用原始字符串避免转义) |
|
|
|
|
|
|
|
# pid = 0 |
|
|
|
|
|
|
|
# orderId = 0 |
|
|
|
|
|
|
|
# styleNumber = 0 |
|
|
|
|
|
|
|
# downloadPath = r"D:\downloadPhotos" |
|
|
|
|
|
|
|
# inputFolder = r"C:\deep" # 实际路径请确认 |
|
|
|
|
|
|
|
# outputFolder = r"C:\StableDiffusion_xiaoyu_V3\ComfyUI-aki-v1.6-XY\ComfyUI\output" |
|
|
|
|
|
|
|
# jsonFilePath = r"C:\StableDiffusion_xiaoyu_V3\ComfyUI-aki-v1.6-XY\ComfyUI\pysssss-workflows" |
|
|
|
|
|
|
|
# driver_path = r"D:\chromedriver-win64\chromedriver.exe" # ChromeDriver路径 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 检查并创建文件夹 |
|
|
|
|
|
|
|
# for folder in [inputFolder, outputFolder, jsonFilePath, downloadPath]: |
|
|
|
|
|
|
|
# if not os.path.exists(folder): |
|
|
|
|
|
|
|
# os.makedirs(folder) |
|
|
|
|
|
|
|
# print(f"创建文件夹:{folder}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 处理命令行参数 |
|
|
|
|
|
|
|
# arrArgs = sys.argv |
|
|
|
|
|
|
|
# if len(arrArgs) == 4: |
|
|
|
|
|
|
|
# pid = arrArgs[1] |
|
|
|
|
|
|
|
# orderId = arrArgs[2] |
|
|
|
|
|
|
|
# styleNumber = arrArgs[3] |
|
|
|
|
|
|
|
# # 判断是否是数字 |
|
|
|
|
|
|
|
# if pid.isdigit() and orderId.isdigit() and styleNumber.isdigit(): |
|
|
|
|
|
|
|
# main(int(pid), int(orderId), int(styleNumber)) # 转为int避免字符串比较问题 |
|
|
|
|
|
|
|
# else: |
|
|
|
|
|
|
|
# print("输入的参数不是数字") |
|
|
|
|
|
|
|
# else: |
|
|
|
|
|
|
|
# # 从Redis消费任务 |
|
|
|
|
|
|
|
# while True: |
|
|
|
|
|
|
|
# try: |
|
|
|
|
|
|
|
# r = utils.create_redis_connection() |
|
|
|
|
|
|
|
# info = r.spop('model:badge_cartoon') |
|
|
|
|
|
|
|
# if info is None: |
|
|
|
|
|
|
|
# print('队列为空,等待10秒') |
|
|
|
|
|
|
|
# time.sleep(10) |
|
|
|
|
|
|
|
# continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 确保info是字符串类型 |
|
|
|
|
|
|
|
# if isinstance(info, bytes): |
|
|
|
|
|
|
|
# info = info.decode('utf-8') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 解析JSON |
|
|
|
|
|
|
|
# info_dict = json.loads(info) |
|
|
|
|
|
|
|
# print(f"从Redis获取任务:{info_dict}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 检查必要的字段是否存在 |
|
|
|
|
|
|
|
# if not all(key in info_dict for key in ['pid', 'order_id', 'style_number']): |
|
|
|
|
|
|
|
# err_msg = f"Redis数据格式错误,缺少必要字段: {info_dict}" |
|
|
|
|
|
|
|
# print(err_msg) |
|
|
|
|
|
|
|
# utils.notify(err_msg) |
|
|
|
|
|
|
|
# continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 转换为整数 |
|
|
|
|
|
|
|
# pid = int(info_dict['pid']) |
|
|
|
|
|
|
|
# orderId = int(info_dict['order_id']) |
|
|
|
|
|
|
|
# styleNumber = int(info_dict['style_number']) |
|
|
|
|
|
|
|
# print(f"开始处理任务 - pid:{pid} orderId:{orderId} style_number:{styleNumber}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 创建临时文件标记 |
|
|
|
|
|
|
|
# tempFile = os.path.join(downloadPath, f"{pid}_{orderId}_{styleNumber}.txt") |
|
|
|
|
|
|
|
# with open(tempFile, 'w', encoding='utf-8') as f: |
|
|
|
|
|
|
|
# f.write(f"任务开始时间:{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 执行主任务 |
|
|
|
|
|
|
|
# main(pid, orderId, styleNumber) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# except json.JSONDecodeError as e: |
|
|
|
|
|
|
|
# err_msg = f'JSON解析错误:{str(e)}\n原始数据:{info if "info" in locals() else "未知"}\n堆栈:{traceback.format_exc()}' |
|
|
|
|
|
|
|
# print(err_msg) |
|
|
|
|
|
|
|
# utils.notify(err_msg) |
|
|
|
|
|
|
|
# # 写入错误标记文件 |
|
|
|
|
|
|
|
# if 'pid' in locals() and 'orderId' in locals() and 'styleNumber' in locals(): |
|
|
|
|
|
|
|
# tempFile = os.path.join(downloadPath, f"{pid}_{orderId}_{styleNumber}_解析错误.txt") |
|
|
|
|
|
|
|
# with open(tempFile, 'w', encoding='utf-8') as f: |
|
|
|
|
|
|
|
# f.write(err_msg) |
|
|
|
|
|
|
|
# time.sleep(10) |
|
|
|
|
|
|
|
# continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# except Exception as e: |
|
|
|
|
|
|
|
# err_msg = f'执行任务异常:{str(e)}\n堆栈:{traceback.format_exc()}' |
|
|
|
|
|
|
|
# print(err_msg) |
|
|
|
|
|
|
|
# utils.notify(err_msg) |
|
|
|
|
|
|
|
# # 修复:异常对象转字符串后写入文件 |
|
|
|
|
|
|
|
# if 'pid' in locals() and 'orderId' in locals() and 'styleNumber' in locals(): |
|
|
|
|
|
|
|
# tempFile = os.path.join(downloadPath, f"{pid}_{orderId}_{styleNumber}_异常错误.txt") |
|
|
|
|
|
|
|
# with open(tempFile, 'w', encoding='utf-8') as f: |
|
|
|
|
|
|
|
# f.write(err_msg) |
|
|
|
|
|
|
|
# time.sleep(10) |
|
|
|
|
|
|
|
# continue |
|
|
|
|