提交 04deaad2 作者: 薛凌堃

使用多线程补采公告

上级 0227ff97
"""
"""
......@@ -19,12 +19,15 @@ from urllib.parse import unquote
baseCore = BaseCore.BaseCore()
log = baseCore.getLogger()
baseCore = BaseCore.BaseCore()
local = threading.local()
# 使用连接池
cnx_ = baseCore.pool_11.connection()
# cnx_ = baseCore.pool_11.connection()
# cursor_ = cnx_.cursor()
cnx_ = baseCore.cnx_
cursor_ = cnx_.cursor()
lock = threading.Lock()
pathType = 'QYNotice/'
taskType = '企业公告/证监会'
obsClient = ObsClient(
......@@ -101,15 +104,6 @@ class EsMethod(object):
,body=body)
log.info('更新结果:%s' % result)
# 获取当前线程的数据库连接
def get_connection():
# 检查当前线程是否已经有连接对象
if not hasattr(local, 'conn'):
# 如果没有,则创建一个连接对象并保存到thread-local中
local.conn = baseCore.pool_11.connection()
return local.conn
def getuuid():
get_timestamp_uuid = uuid.uuid1() # 根据 时间戳生成 uuid , 保证全球唯一
return get_timestamp_uuid
......@@ -185,9 +179,12 @@ def getOBSres(pathType,name, response):
return result
def secrchATT(item_id, retData, type_id,order_by):
sel_sql = '''select id from clb_sys_attachment where item_id = %s and path = %s and type_id=%s and order_by=%s '''
lock.acquire()
cursor_.execute(sel_sql, (item_id, retData['path'], type_id,order_by))
selects = cursor_.fetchone()
lock.release()
return selects
# 插入到att表 返回附件id
......@@ -219,11 +216,13 @@ def tableUpdate(retData, year, pdf_name, num,pub_time,origin):
status, create_by,
create_time, page_size, full_path.split('https://zzsn.obs.cn-north-1.myhuaweicloud.com/')[1], 'zzsn',
pub_time, origin)
lock.acquire()
cursor_.execute(Upsql, values) # 插入
cnx_.commit() # 提交
lock.release()
except Exception as e:
log.info(e)
return ''
log.info(f"更新完成:{item_id}===={pdf_name}")
selects = secrchATT(item_id, retData, type_id,order_by)
id = selects[0]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论