|
|
|
@ -53,7 +53,40 @@ class RedisClientSingleton: |
|
|
|
|
|
|
|
|
|
|
|
def get_client(self): |
|
|
|
def get_client(self): |
|
|
|
if self._client is None: |
|
|
|
if self._client is None: |
|
|
|
self._client = redis.Redis(host='mp.api.suwa3d.com', password='kcV2000', port=6379, db=6) |
|
|
|
# 添加超时参数,防止连接超时 |
|
|
|
|
|
|
|
# socket_timeout: 每次操作的超时时间(秒) |
|
|
|
|
|
|
|
# socket_connect_timeout: 连接超时时间(秒) |
|
|
|
|
|
|
|
# socket_keepalive: 启用 TCP keepalive |
|
|
|
|
|
|
|
# socket_keepalive_options: keepalive 选项 |
|
|
|
|
|
|
|
self._client = redis.Redis( |
|
|
|
|
|
|
|
host='mp.api.suwa3d.com', |
|
|
|
|
|
|
|
password='kcV2000', |
|
|
|
|
|
|
|
port=6379, |
|
|
|
|
|
|
|
db=6, |
|
|
|
|
|
|
|
socket_timeout=30, # 操作超时30秒 |
|
|
|
|
|
|
|
socket_connect_timeout=10, # 连接超时10秒 |
|
|
|
|
|
|
|
socket_keepalive=True, # 启用 TCP keepalive |
|
|
|
|
|
|
|
socket_keepalive_options={}, # keepalive 选项 |
|
|
|
|
|
|
|
health_check_interval=30 # 健康检查间隔30秒 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
# 检查连接是否有效,如果断开则重新连接 |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
self._client.ping() |
|
|
|
|
|
|
|
except (redis.ConnectionError, redis.TimeoutError, AttributeError): |
|
|
|
|
|
|
|
# 连接断开,重新创建连接 |
|
|
|
|
|
|
|
self._client = None |
|
|
|
|
|
|
|
self._client = redis.Redis( |
|
|
|
|
|
|
|
host='mp.api.suwa3d.com', |
|
|
|
|
|
|
|
password='kcV2000', |
|
|
|
|
|
|
|
port=6379, |
|
|
|
|
|
|
|
db=6, |
|
|
|
|
|
|
|
socket_timeout=30, |
|
|
|
|
|
|
|
socket_connect_timeout=10, |
|
|
|
|
|
|
|
socket_keepalive=True, |
|
|
|
|
|
|
|
socket_keepalive_options={}, |
|
|
|
|
|
|
|
health_check_interval=30 |
|
|
|
|
|
|
|
) |
|
|
|
return self._client |
|
|
|
return self._client |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -67,12 +100,20 @@ def redisClient(): |
|
|
|
def requestApiToUpdateSliceStatus(versionId,downloadCounts): |
|
|
|
def requestApiToUpdateSliceStatus(versionId,downloadCounts): |
|
|
|
api_url = f"{url}/api/printTypeSettingOrder/updateBatchSliceing?batch_id={versionId}&download_counts="+str(downloadCounts) |
|
|
|
api_url = f"{url}/api/printTypeSettingOrder/updateBatchSliceing?batch_id={versionId}&download_counts="+str(downloadCounts) |
|
|
|
print(f'发起状态变更请求url={api_url}, versionId={versionId}') |
|
|
|
print(f'发起状态变更请求url={api_url}, versionId={versionId}') |
|
|
|
res = requests.post(api_url) |
|
|
|
try: |
|
|
|
|
|
|
|
# 添加超时参数,防止请求时间过长 |
|
|
|
|
|
|
|
res = requests.post(api_url, timeout=60) # 60秒超时 |
|
|
|
if res.status_code != 200: |
|
|
|
if res.status_code != 200: |
|
|
|
print(f'状态变更请求失败, res={res.text}') |
|
|
|
print(f'状态变更请求失败, res={res.text}') |
|
|
|
return False |
|
|
|
return False |
|
|
|
print(f'状态变更请求成功, res={res.text}') |
|
|
|
print(f'状态变更请求成功, res={res.text}') |
|
|
|
return True |
|
|
|
return True |
|
|
|
|
|
|
|
except requests.exceptions.Timeout: |
|
|
|
|
|
|
|
print(f'状态变更请求超时, url={api_url}') |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
except requests.exceptions.RequestException as e: |
|
|
|
|
|
|
|
print(f'状态变更请求异常, error={str(e)}') |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
#判断是否上传了 JSON 文件 |
|
|
|
#判断是否上传了 JSON 文件 |
|
|
|
def step1(versionId): |
|
|
|
def step1(versionId): |
|
|
|
@ -144,6 +185,7 @@ def step2(jsonFilePath,folder, versionId): |
|
|
|
# 直接调用函数,而不是通过os.system执行python命令 |
|
|
|
# 直接调用函数,而不是通过os.system执行python命令 |
|
|
|
# 这样可以避免在打包成exe后找不到python命令的问题 |
|
|
|
# 这样可以避免在打包成exe后找不到python命令的问题 |
|
|
|
workdir = os.path.join(folder, 'data') |
|
|
|
workdir = os.path.join(folder, 'data') |
|
|
|
|
|
|
|
print(f"模型数据存储目录={workdir}, jsonFilePath={jsonFilePath}") |
|
|
|
download_transform_save_by_json(jsonFilePath, workdir, '') |
|
|
|
download_transform_save_by_json(jsonFilePath, workdir, '') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -186,11 +228,11 @@ def main(work_dir=None): |
|
|
|
versionId = str(data) |
|
|
|
versionId = str(data) |
|
|
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 正在处理版次ID={versionId}') |
|
|
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 正在处理版次ID={versionId}') |
|
|
|
|
|
|
|
|
|
|
|
#执行前,先删除可能存在的旧数据目录(包括 _big 和 _small) |
|
|
|
#执行前,先删除可能存在的旧数据目录(包括 _big 和 _small),删除整个目录 |
|
|
|
for suffix in ['_big', '_small']: |
|
|
|
for suffix in ['_big', '_small']: |
|
|
|
objFilePath = os.path.join(currentDir, 'batchPrint', versionId + suffix, 'data') |
|
|
|
objFilePath = os.path.join(currentDir, 'batchPrint', versionId + suffix) |
|
|
|
if os.path.exists(objFilePath): |
|
|
|
if os.path.exists(objFilePath): |
|
|
|
shutil.rmtree(objFilePath) |
|
|
|
shutil.rmtree(objFilePath, ignore_errors=True) |
|
|
|
|
|
|
|
|
|
|
|
res = step1(versionId) |
|
|
|
res = step1(versionId) |
|
|
|
if res == False: |
|
|
|
if res == False: |
|
|
|
@ -215,6 +257,15 @@ def main(work_dir=None): |
|
|
|
if file.endswith('.obj'): |
|
|
|
if file.endswith('.obj'): |
|
|
|
objCounts += 1 |
|
|
|
objCounts += 1 |
|
|
|
requestApiToUpdateSliceStatus(versionId,objCounts) |
|
|
|
requestApiToUpdateSliceStatus(versionId,objCounts) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 在长时间操作后,确保 Redis 连接仍然有效 |
|
|
|
|
|
|
|
# 通过重新获取客户端来触发连接检查 |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
r = redisClient() |
|
|
|
|
|
|
|
r.ping() # 测试连接 |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
|
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} Redis连接检查失败: {str(e)},将在下次循环时自动重连') |
|
|
|
|
|
|
|
|
|
|
|
#time.sleep(10) |
|
|
|
#time.sleep(10) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|