redis 链接超时断开的修改
This commit is contained in:
1 parent
00819685b3
commit
7dcba99bb8
2 files changed
+47
-3
No files matched your search
+22
-2
@@ -158,7 +158,7 @@ def team_check(r):
|
|||||||
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), 'redis连接异常,5秒后重试')
|
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), 'redis连接异常,5秒后重试')
|
||||||
print(e)
|
print(e)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
r = redis.Redis(host='106.14.158.208', password='kcV2000', port=6379, db=6)
|
r = create_redis_connection()
|
||||||
return
|
return
|
||||||
repair_id = r.lpop('model:IndependentRepairTeamcheckGLBQueue')
|
repair_id = r.lpop('model:IndependentRepairTeamcheckGLBQueue')
|
||||||
if repair_id is None: return
|
if repair_id is None: return
|
||||||
@@ -239,12 +239,32 @@ def objToGlbAndUpload(pid):
|
|||||||
oss_client.put_object_from_file(f'glbs/print/{glb_filename}', os.path.join(workdir, "print", pid, glb_filename))
|
oss_client.put_object_from_file(f'glbs/print/{glb_filename}', os.path.join(workdir, "print", pid, glb_filename))
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
def main(r):
|
def main(r):
|
||||||
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), '模型生成程序 start')
|
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), '模型生成程序 start')
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
team_check(r)
|
team_check(r)
|
||||||
# platform_check(r)
|
# platform_check(r)
|
||||||
#make3d4print_task(r)
|
#make3d4print_task(r)
|
||||||
|
except Exception as e:
|
||||||
|
print('出现异常:', e)
|
||||||
|
time.sleep(5)
|
||||||
|
r = create_redis_connection()
|
||||||
|
continue
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
atexit.register(common.notify,"R13-修模师审核通过,生成打印任务程序停止")
|
atexit.register(common.notify,"R13-修模师审核通过,生成打印任务程序停止")
|
||||||
@@ -266,5 +286,5 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
blenderbin = find_blender_bin_path()
|
blenderbin = find_blender_bin_path()
|
||||||
|
|
||||||
r = redis.Redis(host='106.14.158.208', password='kcV2000', port=6379, db=6)
|
r = create_redis_connection()
|
||||||
main(r)
|
main(r)
|
||||||
+25
-1
@@ -5,7 +5,23 @@ else:
|
|||||||
sys.path.append('/data/deploy/make3d/make2/libs/')
|
sys.path.append('/data/deploy/make3d/make2/libs/')
|
||||||
|
|
||||||
import config,libs,libs_db,common
|
import config,libs,libs_db,common
|
||||||
r = redis.Redis(host="106.14.158.208",password="kcV2000",port=6379,db=6)
|
|
||||||
|
|
||||||
|
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):
|
def getPSid(pid):
|
||||||
res = requests.get("https://mp.api.suwa3d.com/api/customerP3dLog/photoStudio",params={"pid":pid})
|
res = requests.get("https://mp.api.suwa3d.com/api/customerP3dLog/photoStudio",params={"pid":pid})
|
||||||
res = json.loads(res.text)
|
res = json.loads(res.text)
|
||||||
@@ -60,6 +76,7 @@ if __name__ == '__main__':
|
|||||||
#print(r.llen('model:make10'))
|
#print(r.llen('model:make10'))
|
||||||
#开启死循环
|
#开启死循环
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-读取redis中的任务")
|
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-读取redis中的任务")
|
||||||
# 3D相册建模队列 model:make_experience
|
# 3D相册建模队列 model:make_experience
|
||||||
# model:make model:make10
|
# model:make model:make10
|
||||||
@@ -68,3 +85,10 @@ if __name__ == '__main__':
|
|||||||
readTask('make')
|
readTask('make')
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
readTask("rebuild")
|
readTask("rebuild")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f'出现异常:{e}')
|
||||||
|
time.sleep(30)
|
||||||
|
r = create_redis_connection()
|
||||||
|
continue
|
||||||
|
|
||||||
Reference in new issue
Block a user