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.
112 lines
4.1 KiB
112 lines
4.1 KiB
import platform,sys,redis,time,requests,json,atexit |
|
if platform.system() == 'Windows': |
|
sys.path.append('e:\\libs\\') |
|
else: |
|
sys.path.append('/data/deploy/make3d/make2/libs/') |
|
|
|
import config,libs,libs_db,common |
|
|
|
|
|
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) |
|
|
|
r = create_redis_connection() |
|
|
|
def getPSid(pid): |
|
res = requests.get("https://mp.api.suwa3d.com/api/customerP3dLog/photoStudio",params={"pid":pid}) |
|
res = json.loads(res.text) |
|
return str(res['data']) |
|
|
|
def get_ps_type(pid): |
|
# return 1:圆形影棚 2:方形影棚 |
|
res = requests.get("https://mp.api.suwa3d.com/api/takephotoOrder/photoStudioInfo", params={'pid': pid}) |
|
return res.json()['data']['type'] |
|
|
|
|
|
|
|
def readTask(key): |
|
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-读取队列-"+'model:'+key) |
|
if r.llen('model:'+key) == 0: |
|
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-没有查询到任务在"+key+"队列中") |
|
return |
|
#读取一个值 |
|
pid = r.lpop('model:'+key) |
|
#判断是否为空 |
|
if pid is None: |
|
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-读取的PID为空") |
|
return |
|
pid = pid.decode('utf-8') |
|
|
|
#判断影棚类型 |
|
ps_type = get_ps_type(pid) |
|
if ps_type == 2: |
|
#方形影棚 |
|
# r.rpush('ai:ai_repeat_build',pid) |
|
r.rpush('ai:ai_repeat_build',pid) |
|
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-方形影棚数据推入到新的建模方式的重建队列") |
|
common.notify("方形影棚数据推入到新的建模方式的重建队列 (ai:ai_repeat_build),pid="+pid) |
|
return |
|
psid = getPSid(pid) |
|
|
|
#判断是否走新的建模系统 2023-11-10 全部走新的建模系统 |
|
# if libs_db.is_new_make_psid(psid) == False: |
|
# #如果不是走新的建模系统就塞回原来的队列 |
|
# print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-该任务不是走新的建模任务,塞回原来的队列-"+pid) |
|
# r.rpush('model:'+key,pid) |
|
# return |
|
#新的建模系统 |
|
#psid = getPSid(pid) |
|
if key == "make10": |
|
key = "make" |
|
|
|
#默认走原来的数据表tasks,现在要切入一些数据过来走分布式建模系统 |
|
taskData = {"task_type":key,"task_key":pid,"psid":psid,"priority":1} |
|
|
|
if key == "rebuild": |
|
taskData["priority"] = 100 |
|
print("走新的建模系统不是分布式插入-重建工单",key,pid,psid) |
|
libs_db.add_task(taskData) |
|
else: |
|
# intPid = int(psid) |
|
# if intPid == 29 or intPid == 94 or intPid == 51: |
|
# libs_db.add_task(taskData) |
|
# elif int(psid) <= 90 and int(psid) != 29 and int(psid) != 56 and int(psid) != 1: |
|
# print("走分布式建模",key,pid,psid) |
|
# if int(psid) == 41 or int(psid) == 85: |
|
# taskData["priority"] = 0 |
|
# libs_db.add_task_distributed(taskData) |
|
# else: |
|
print("非分布式建模",key,pid,psid) |
|
libs_db.add_task(taskData) |
|
#程序主入口 |
|
if __name__ == '__main__': |
|
atexit.register(common.notify,"定时读取建模任务已经停止") |
|
#print(r.llen('model:make10')) |
|
#开启死循环 |
|
while True: |
|
try: |
|
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-读取redis中的任务") |
|
# 3D相册建模队列 model:make_experience |
|
# model:make model:make10 |
|
readTask('make10') |
|
time.sleep(10) |
|
readTask('make') |
|
time.sleep(10) |
|
readTask("rebuild") |
|
|
|
except Exception as e: |
|
print(f'出现异常:{e}') |
|
time.sleep(30) |
|
r = create_redis_connection() |
|
continue |
|
|