You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.4 KiB
94 lines
3.4 KiB
import redis,time,requests,json,os |
|
|
|
|
|
def getOrderInfoByOrderId(orderId): |
|
try: |
|
|
|
url = "https://mp.api.suwa3d.com/api/physical/infoModelSizeByOrderId?order_id="+str(orderId) |
|
print("url:",url) |
|
res = requests.get(url) |
|
if res.status_code != 200: |
|
print('获取失败,程序退出') |
|
return "error","error" |
|
print("res",res) |
|
res = json.loads(res.text) |
|
print("res",res) |
|
#获取到model_size |
|
modelSize = res['data']['model_size'] |
|
pid = res['data']['pid'] |
|
return pid,modelSize |
|
|
|
except Exception as e: |
|
print(f"获取订单信息异常: {str(e)}") |
|
return "error","error" |
|
|
|
def create_redis_connection(): |
|
"""创建 Redis 连接,若连接失败则重试""" |
|
while True: |
|
try: |
|
r = redis.Redis(host="106.14.158.208",password="kcV2000",port=6379,db=6) |
|
# 尝试进行一次操作,检查连接是否有效 |
|
r.ping() # ping 操作是一个简单的连接测试 |
|
print("Redis连接成功!") |
|
return r |
|
except ConnectionError: |
|
print("Redis连接失败,正在重试...") |
|
time.sleep(5) |
|
|
|
|
|
if __name__ == '__main__': |
|
r = create_redis_connection() |
|
while True: |
|
try: |
|
print(f"时间-{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}") |
|
if r.llen('model:weight') == 0: |
|
print('队列为空,等待10秒') |
|
time.sleep(10) |
|
continue |
|
|
|
# info 的数据格式为有以下几种情况 1. orderId 2 orderId_print_9,1.2,45,27 3. orderId_auto_9,1.2,45,27 |
|
info = r.lpop('model:weight') |
|
if info is None: |
|
print('队列为空,等待10秒') |
|
time.sleep(10) |
|
info = info.decode('utf-8') |
|
orderId = 0 |
|
pid = 0 |
|
modelSize = [] |
|
typeModel = "print" |
|
#判断info是什么类型的数据 |
|
arrInfo = info.split("_") |
|
if len(arrInfo) == 1: |
|
orderId = arrInfo[0] |
|
pid,modelSize = getOrderInfoByOrderId(orderId) |
|
if pid == "error": |
|
print("获取订单信息失败") |
|
continue |
|
|
|
elif len(arrInfo) == 3: |
|
orderId = arrInfo[0] |
|
pid,temp = getOrderInfoByOrderId(orderId) |
|
if pid == "error": |
|
print("获取订单信息失败") |
|
continue |
|
typeModel = arrInfo[1] |
|
modelSize = arrInfo[2] |
|
if typeModel != "print" and typeModel != "auto": |
|
print("typeModel类型不对") |
|
continue |
|
|
|
|
|
if int(orderId) == 0 or int(pid) == 0 or len(modelSize) == 0: |
|
print("orderId pid modelSize 有出现问题") |
|
continue |
|
|
|
#转成数组 |
|
arrModelSize = modelSize.split(",") |
|
print(f'执行脚本--- "python D:/make2/tools/cal_weight.py {typeModel} {pid} {modelSize} {orderId}"') |
|
#发起计算请求 |
|
os.system(f"python D:/make2/tools/cal_weight.py {typeModel} {pid} {modelSize} {orderId}") |
|
except Exception as e: |
|
print(f"执行脚本异常: {str(e)}") |
|
time.sleep(10) |
|
r = create_redis_connection() |
|
continue
|
|
|