@ -2,16 +2,20 @@
import pymysql , socket , time
import pymysql , socket , time
import config
import config
# 获取新的任务
#公共连接库
def get_task ( task_type ) :
def pymysqlAlias ( ) :
try :
return pymysql . connect (
with pymysql . connect (
host = config . mysql_local [ ' host ' ] ,
host = config . mysql_local [ ' host ' ] ,
port = config . mysql_local [ ' port ' ] ,
port = config . mysql_local [ ' port ' ] ,
user = config . mysql_local [ ' user ' ] ,
user = config . mysql_local [ ' user ' ] ,
password = config . mysql_local [ ' password ' ] ,
password = config . mysql_local [ ' password ' ] ,
db = config . mysql_local [ ' db ' ] ,
db = config . mysql_local [ ' db ' ] ,
charset = config . mysql_local [ ' charset ' ] , ) as conn :
charset = config . mysql_local [ ' charset ' ] , )
# 获取新的任务
def get_task ( task_type ) :
try :
with pymysqlAlias ( ) as conn :
cursor = conn . cursor ( )
cursor = conn . cursor ( )
sql = f ' select task_key from tasks where task_type = " { task_type } " and status = 0 order by priority desc, id asc limit 1 '
sql = f ' select task_key from tasks where task_type = " { task_type } " and status = 0 order by priority desc, id asc limit 1 '
@ -29,13 +33,7 @@ def get_task(task_type):
# 新增新的任务
# 新增新的任务
def add_task ( data ) :
def add_task ( data ) :
try :
try :
with pymysql . connect (
with pymysqlAlias ( ) as conn :
host = config . mysql_local [ ' host ' ] ,
port = config . mysql_local [ ' port ' ] ,
user = config . mysql_local [ ' user ' ] ,
password = config . mysql_local [ ' password ' ] ,
db = config . mysql_local [ ' db ' ] ,
charset = config . mysql_local [ ' charset ' ] , ) as conn :
cursor = conn . cursor ( )
cursor = conn . cursor ( )
#判断是否是昆山教学的,是的话优先级设置为默认
#判断是否是昆山教学的,是的话优先级设置为默认
@ -55,13 +53,7 @@ def add_task(data):
# 开始任务
# 开始任务
def start_task ( data ) :
def start_task ( data ) :
try :
try :
with pymysql . connect (
with pymysqlAlias ( ) as conn :
host = config . mysql_local [ ' host ' ] ,
port = config . mysql_local [ ' port ' ] ,
user = config . mysql_local [ ' user ' ] ,
password = config . mysql_local [ ' password ' ] ,
db = config . mysql_local [ ' db ' ] ,
charset = config . mysql_local [ ' charset ' ] , ) as conn :
cursor = conn . cursor ( )
cursor = conn . cursor ( )
hostname = socket . gethostname ( )
hostname = socket . gethostname ( )
@ -75,13 +67,7 @@ def start_task(data):
# 完成任务
# 完成任务
def finish_task ( data ) :
def finish_task ( data ) :
try :
try :
with pymysql . connect (
with pymysqlAlias ( ) as conn :
host = config . mysql_local [ ' host ' ] ,
port = config . mysql_local [ ' port ' ] ,
user = config . mysql_local [ ' user ' ] ,
password = config . mysql_local [ ' password ' ] ,
db = config . mysql_local [ ' db ' ] ,
charset = config . mysql_local [ ' charset ' ] , ) as conn :
cursor = conn . cursor ( )
cursor = conn . cursor ( )
hostname = socket . gethostname ( )
hostname = socket . gethostname ( )
@ -91,3 +77,45 @@ def finish_task(data):
conn . commit ( )
conn . commit ( )
except Exception as e :
except Exception as e :
print ( f " { time . strftime ( ' % Y- % m- %d % H: % M: % S ' , time . localtime ( ) ) } 执行finish_task( { data } )异常: { str ( 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 , is_default = False ) :
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 } ) '
# print(f'sql: {sql}')
cursor . execute ( sql )
result = cursor . fetchall ( )
if is_default :
return result [ 0 ] [ " value " ]
if len ( result ) == 1 :
return result [ 0 ] [ " value " ]
if len ( result ) == 2 :
for item in result :
if item [ " studio_id " ] == psid :
return item [ " value " ]
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 "