同步更改数据

This commit is contained in:
dongchangxi committed 2024-07-17 14:46:47 +08:00
1 parent ecb58b2f59
commit 33ba8bb357
21 files changed
+2019472 -63

No files matched your search

+25 -5
View File
@@ -18,17 +18,37 @@ ali_oss = {
oss_bucket = oss2.Bucket(oss2.Auth(ali_oss['access_key_id'], ali_oss['access_key_secret']), ali_oss['endpoint'], ali_oss['bucket_name'])
redis_remote = redis.Redis(host='106.14.158.208', password='kcV2000', port=6379, db=6)
redis_local = redis.Redis(host='172.16.20.13', password='ph2008', port=6379, db=0)
redis_local_common = redis.Redis(host='172.16.20.13', password='ph2008', port=6379, db=1)
redis_local = redis.Redis(host='172.31.1.254', password='', port=6379, db=0)
redis_local_common = redis.Redis(host='172.31.1.254', password='', port=6379, db=1)
mysql_local = {
"host": "172.16.20.13",
"port": 3306,
"host": '172.31.1.254',#"172.16.20.13",
"port": 23306,
"user": "pi",
"password": "ph2008",
"db": "suwa3d",
"charset": "utf8mb4"
}
mysql_gpu = {
"host": 'rm-uf64l0683d2t2jt1c3o.mysql.rds.aliyuncs.com',
"port": 3306,
"user": "airepair",
"password": "Ai_repair@suwa3d",
"db": "ai_repair",
"charset": "utf8"
}
mysql_dong = {
"host": "172.31.1.254",
"port": 13306,
"user": "api",
"password": "api2022",
"db": "new_suwa3d",
"charset": "utf8mb4"
}
if platform.system() == 'Windows':
workdir = 'D:\\'
sharedir = 'E:\\'
@@ -137,4 +157,4 @@ high_host = ["R11","R12"]
low_host = ["R13","R14","R15","R16","R17"]
#不参与贴图的照片,使用的时候还需要增加指令 python main_step1.py 123 no_texture
noTextureColorPics = ["13", "23", "31", "52", "72", "82", "142", "173"] # 昆山老數據不慘與貼圖["134","135","136","142","143","14","15","16","24","25","26","44","45"]
noTextureColorPics = ["13", "23", "31", "52", "72", "82", "142", "173"] #["134","135","136","142","143","14","15","16","24","25","26","44","45"]
+24
View File
@@ -307,3 +307,27 @@ def diff_time(start_time):
m, s = divmod(diff, 60)
return f'{int(m)}分{int(s)}秒'
def down_obj_from_oss_for_fix(workdir, pid, action):
if os.path.exists(os.path.join(workdir, action, pid)):
print(f'目录{os.path.join(workdir, action, pid)}已存在,跳过')
return
else:
os.makedirs(os.path.join(workdir, action, pid))
# 根据前缀获取文件列表
prefix = f'objs/{action}/{pid}/'
filelist = oss2.ObjectIteratorV2(config.oss_bucket, prefix=prefix)
print('正在下载:', prefix)
obj_filename = ""
for file in filelist:
filename = file.key.split('/')[-1]
if filename.endswith(f'{pid}.obj') == False:
continue
if filename.endswith('.obj'):
obj_filename = filename
# print('正在下载:', file.key)
localfile = os.path.join(workdir, action, pid, filename)
config.oss_bucket.get_object_to_file(file.key, localfile)
return obj_filename
+213
View File
@@ -0,0 +1,213 @@
# mysql数据库常用任务函数封装
import pymysql, socket, time
import config
#公共连接库
def pymysqlAlias():
return pymysql.connect(
host=config.mysql_dong['host'],
port=config.mysql_dong['port'],
user=config.mysql_dong['user'],
password=config.mysql_dong['password'],
db=config.mysql_dong['db'],
charset=config.mysql_dong['charset'],)
# 获取新的任务
def get_task_by_level():
try:
with pymysqlAlias() as conn:
cursor = conn.cursor()
sql = f'select pid from pid_base_fix where status = 0 order by level desc, id asc limit 1'
# print(f'sql: {sql}')
cursor.execute(sql)
data = cursor.fetchone()
if data:
return data[0]
else:
return ''
except Exception as e:
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} get_task_by_level()异常: {str(e)}")
return ''
# 开始任务
def update_fix_status(pid,status):
try:
with pymysqlAlias() as conn:
cursor = conn.cursor()
hostname = socket.gethostname()
sql = f'update pid_base_fix set status = {status},createTime = now(), updateTime = now() where status = 0 and pid = {pid}'
print(f'开始任务sql: {sql}')
cursor.execute(sql)
conn.commit()
except Exception as e:
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行update_fix_status()异常: {str(e)}")
# # 获取新的任务
# def get_task(task_type):
# try:
# with pymysqlAlias() as conn:
# cursor = conn.cursor()
# sql = f'select task_key from tasks where status = 0 order by priority desc, id asc limit 1 for update'
# # print(f'sql: {sql}')
# cursor.execute(sql)
# data = cursor.fetchone()
# if data:
# return data[0]
# else:
# return ''
# except Exception as e:
# print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行get_task({task_type})异常: {str(e)}")
# return ''
# # 新增新的任务
# def add_task(data):
# try:
# with pymysqlAlias() as conn:
# cursor = conn.cursor()
# #判断是否是昆山教学的,是的话优先级设置为默认
# if data["psid"] == '85':
# sql = f'insert into tasks (task_type, task_key,studio_id) values ("{data["task_type"]}", "{data["task_key"]}","{data["psid"]}")'
# else:
# sql = f'insert into tasks (task_type, task_key, priority,studio_id) values ("{data["task_type"]}", "{data["task_key"]}", {data["priority"]},"{data["psid"]}")'
# # print(f'sql: {sql}')
# cursor.execute(sql)
# conn.commit()
# 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):
# flag = isInTaskDistributed(data["task_key"])
# if flag:
# return "already"
# 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:
# with pymysqlAlias() as conn:
# cursor = conn.cursor()
# hostname = socket.gethostname()
# sql = f'update tasks set status = 1, hostname = "{hostname}", started_at = now(), updated_at = now() where status = 0 and task_key = {data["task_key"]}'
# print(f'开始任务sql: {sql}')
# cursor.execute(sql)
# conn.commit()
# except Exception as e:
# print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行start_task({data})异常: {str(e)}")
# # 完成任务
# def finish_task(data):
# try:
# with pymysqlAlias() as conn:
# cursor = conn.cursor()
# hostname = socket.gethostname()
# sql = f'update tasks set status = 2, hostname = "{hostname}", finished_at = now(), updated_at = now() where status = 1 and task_key = "{data["task_key"]}" '
# # print(f'sql: {sql}')
# cursor.execute(sql)
# conn.commit()
# except Exception as e:
# print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行finish_task({data})异常: {str(e)}")
# # 根据影棚ID 获取影棚的配置,如果没有指定的配置,则返回默认配置
# def get_floor_sticker_distances(psid):
# try:
# with pymysqlAlias() as conn:
# cursor = conn.cursor()
# sql = f'select a.studio_id,value from floor_sticker_link_studio as a left join floor_sticker_distances as b on a.floor_name = b.name where a.studio_id in (0,{psid})'
# cursor.execute(sql)
# result = cursor.fetchall()
# if len(result) == 1:
# return result[0][1]
# if len(result) == 2:
# for item in result:
# if str(item[0]) == str(psid):
# return item[1]
# return "error-配置异常,该影棚有多个地贴配置"
# except Exception as e:
# print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行get_floor_sticker_distances()异常: {str(e)}")
# return "error"
# #判断是否要走新的建模系统
# def is_new_make_psid(psid):
# try:
# with pymysqlAlias() as conn:
# cursor = conn.cursor()
# sql = f'select count(*) from new_make_psid where studio_id = {psid}'
# print(f'sql: {sql}')
# cursor.execute(sql)
# result = cursor.fetchone()
# if result[0] > 0:
# return True
# else:
# return False
# except Exception as e:
# print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行is_new_make_psid()异常: {str(e)}")
# return "error"
# #判断影棚是否走的新的建模系统,不是的话修改成走新的建模系统
# def change_to_new_make_psid(psid):
# try:
# with pymysqlAlias() as conn:
# cursor = conn.cursor()
# sql = f'select count(*) from new_make_psid where studio_id = {psid}'
# cursor.execute(sql)
# result = cursor.fetchone()
# if result[0] == 0:
# sql = f'insert into new_make_psid (studio_id,createTime) values ({psid},now())'
# 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} and status = 1'
# 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"
# #判断是否已经存在了
# def isInTaskDistributed(task_key):
# try:
# with pymysqlAlias() as conn:
# cursor = conn.cursor()
# sql = f'select count(*) from task_distributed where status = 0 and task_key = "{task_key}"'
# 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())} 执行isInTaskDistributed()异常: {str(e)}")
# return "error"