优化及bug修改
This commit is contained in:
1 parent
5467bbc232
commit
f4254f0051
9 files changed
+265
-38
No files matched your search
+56
-2
@@ -1,4 +1,4 @@
|
||||
import redis,sys,os,re
|
||||
import redis,sys,os,re,oss2
|
||||
import platform
|
||||
import xml.etree.ElementTree as ET
|
||||
if platform.system() == 'Windows':
|
||||
@@ -140,4 +140,58 @@ def changeRcprojFile(pid):
|
||||
|
||||
# 保存修改后的XML文件
|
||||
tree.write(file_path)
|
||||
return True
|
||||
return True
|
||||
#修改 rcproj 文件中的 controlpoints 文件的引用
|
||||
def changeRcprojControlpointsFile(pid):
|
||||
psid = libs.getPSid(pid)
|
||||
# 解析XML文件
|
||||
file_path = os.path.join(config.workdir, str(pid), f'{pid}.rcproj')
|
||||
#判断文件是否存在
|
||||
if not os.path.exists(file_path):
|
||||
return False
|
||||
#下载指定的psid的 points文件到本地
|
||||
flag = down_points_from_oss(pid,psid)
|
||||
if flag == False:
|
||||
return False
|
||||
tree = ET.parse(file_path)
|
||||
root = tree.getroot()
|
||||
# 遍历所有的reconstructions节点
|
||||
for controlpoints in root.findall('controlpoints'):
|
||||
#修改 controlpoints 标签内容里 双引号的内容 <controlpoints fileName="" />
|
||||
controlpoints.set('fileName',f'controlpoints_{psid}.dat')
|
||||
# 保存修改后的XML文件
|
||||
tree.write(file_path)
|
||||
return True
|
||||
|
||||
|
||||
def down_points_from_oss(pid,psid):
|
||||
# 根据前缀获取文件列表
|
||||
prefix = f'points/{psid}/'
|
||||
filelist = oss2.ObjectIteratorV2(config.oss_bucket, prefix=prefix)
|
||||
flag = False
|
||||
for file in filelist:
|
||||
filename = file.key.split('/')[-1]
|
||||
if filename.endswith('.dat'):
|
||||
# print('正在下载:', file.key)
|
||||
localfile = os.path.join(config.workdir,str(pid), filename)
|
||||
config.oss_bucket.get_object_to_file(file.key, localfile)
|
||||
flag = True
|
||||
return flag
|
||||
|
||||
#判断oss上是否存在指定的controlpoints文件
|
||||
def isExistControlPointsOss(pid):
|
||||
psid = libs.getPSid(pid)
|
||||
filePath = f'points/{psid}/controlpoints_{psid}.dat'
|
||||
#判断oss上是否存在
|
||||
if config.oss_bucket.object_exists(filePath):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
#将本地的controlpoints文件上传到oss上
|
||||
def uploadControlPointsOss(pid):
|
||||
psid = libs.getPSid(pid)
|
||||
filePath = f'points/{psid}/controlpoints_{psid}.dat'
|
||||
localfile = os.path.join(config.workdir,str(pid), f'{str(pid)}_wait/controlpoints0.dat')
|
||||
#进行上传
|
||||
config.oss_bucket.put_object_from_file(filePath, localfile)
|
||||
+29
-3
@@ -39,9 +39,6 @@ def add_task(data):
|
||||
#判断是否是昆山教学的,是的话优先级设置为默认
|
||||
if data["psid"] == '85':
|
||||
sql = f'insert into tasks (task_type, task_key,studio_id) values ("{data["task_type"]}", "{data["task_key"]}","{data["psid"]}")'
|
||||
elif data["psid"] == '1':
|
||||
#实验室的订单走分布式处理
|
||||
sql = f'insert into task_distributed (task_type, task_key, priority,created_at,studio_id) values ("{data["task_type"]}", "{data["task_key"]}", 1,"{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}","{data["psid"]}")'
|
||||
else:
|
||||
sql = f'insert into tasks (task_type, task_key, priority,studio_id) values ("{data["task_type"]}", "{data["task_key"]}", 1,"{data["psid"]}")'
|
||||
# print(f'sql: {sql}')
|
||||
@@ -50,6 +47,18 @@ def add_task(data):
|
||||
except Exception as e:
|
||||
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行add_task({data})异常: {str(e)}")
|
||||
|
||||
#新增任务到分布式处理任务表中 {"task_type":key,"task_key":pid,"psid":psid}
|
||||
def add_task_distributed(data):
|
||||
try:
|
||||
with pymysqlAlias() as conn:
|
||||
cursor = conn.cursor()
|
||||
sql = f'insert into task_distributed (task_type, task_key, priority,created_at,studio_id) values ("{data["task_type"]}", "{data["task_key"]}", "{data["priority"]}","{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}","{data["psid"]}")'
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行add_task_distributed({data})异常: {str(e)}")
|
||||
|
||||
|
||||
# 开始任务
|
||||
def start_task(data):
|
||||
try:
|
||||
@@ -130,6 +139,23 @@ def change_to_new_make_psid(psid):
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
print(f'修改影棚{psid}为走新的建模系统')
|
||||
except Exception as e:
|
||||
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行change_to_new_make_psid()异常: {str(e)}")
|
||||
return "error"
|
||||
|
||||
|
||||
#判断影棚走分布式的建模系统 还是走原来的建模系统
|
||||
def isStudioConfigDistribute(psid):
|
||||
try:
|
||||
with pymysqlAlias() as conn:
|
||||
cursor = conn.cursor()
|
||||
sql = f'select count(*) from studio_config_distribute where studio_id = {psid}'
|
||||
cursor.execute(sql)
|
||||
result = cursor.fetchone()
|
||||
if result[0] == 0:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行change_to_new_make_psid()异常: {str(e)}")
|
||||
return "error"
|
||||
Reference in new issue
Block a user