From 0bf1a59741b5fb83ccfefbba3017be29606f5435 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 2 Jul 2024 10:59:35 +0800 Subject: [PATCH] =?UTF-8?q?add=20workflow=20=E5=A4=A9=E6=B6=A6Smart-ccc?= =?UTF-8?q?=E5=B7=A5=E5=8D=95=E6=95=B0=E6=8D=AE,dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../获取工单记录列表/tickets_list_feign.py | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/dev/workflow/TK_Cust/smart_ccc/获取工单记录列表/tickets_list_feign.py b/dev/workflow/TK_Cust/smart_ccc/获取工单记录列表/tickets_list_feign.py index 337f10f..196815b 100644 --- a/dev/workflow/TK_Cust/smart_ccc/获取工单记录列表/tickets_list_feign.py +++ b/dev/workflow/TK_Cust/smart_ccc/获取工单记录列表/tickets_list_feign.py @@ -84,15 +84,15 @@ def request_data_signature_post(): jsonData = json.dumps(body) print(f'body: {jsonData}') dataReqL=requests.post(url,headers=header,data=jsonData) - + resText = dataReqL.text i = 0 - while 'error' in dataReqL and i < 5: + while 'error' in resText and i < 5: + print(f'请求工单列表失败,再次请求第{i+1}次') time.sleep(1) dataReqL=requests.post(url,headers=header,params=body) i = i + 1 - resL=json.loads(dataReqL.text) + resL=json.loads(resText) print(dataReqL) - resL=json.loads(dataReqL.text) return resL @@ -132,13 +132,15 @@ def request_data_signature_get(id): print(f'url: {url}') dataReqL=requests.get(url,headers={},params={}) + resText = dataReqL.text i = 0 - while 'error' in dataReqL and i < 5: + while 'error' in resText and i < 5: + print(f'请求工单详情失败,再次请求第{i+1}次') time.sleep(1) dataReqL=requests.get(url,headers={},params={}) i = i + 1 - resL=json.loads(dataReqL.text) - return resL + resD=json.loads(resText) + return resD def load_detail_data_to_db(ids, dataList): conn = psycopg2.connect(database="dataops_db", user="dbuser_dops", password="MIgTi3jA",host="172.17.0.8", port="5432") @@ -157,21 +159,21 @@ def load_detail_data_to_db(ids, dataList): print('加载数据结束:tickets_detail:获取工单详情') def load_detail_exp_to_db(id): - print(f'添加查询工单异常记录:{id}') - conn = psycopg2.connect(database="dataops_db", user="dbuser_dops", password="MIgTi3jA",host="172.17.0.8", port="5432") - print('数据库连接成功') - dataId=str(uuid.uuid4()) - total=len(dataList) - print('临时id:'+dataId) - json_object = json.dumps(dataList) - idstr = ','.join(ids) - cur=conn.cursor() - sql=" INSERT INTO data_api.cc_details_ids_exp (id,api_id,is_loaded,status,request_tm,execute_tm,remark) values (%s,%s,'0','0',current_timestamp(0),current_timestamp(0),'')" - cur.execute(sql,[id, '6a977523d60f46788e6004549027bb8e']) - conn.commit() - cur.close() - conn.close() - print(f'添加查询工单异常记录:{id} 结束') + try: + print(f'添加查询工单异常记录:{id}') + conn = psycopg2.connect(database="dataops_db", user="dbuser_dops", password="MIgTi3jA",host="172.17.0.8", port="5432") + print('数据库连接成功') + dataId=str(uuid.uuid4()) + print('临时id:'+dataId) + cur=conn.cursor() + sql=" INSERT INTO data_api.cc_details_ids_exp (id,api_id,is_loaded,status,request_tm,execute_tm,remark) values (%s,%s,'0','0',current_timestamp(0),current_timestamp(0),'')" + cur.execute(sql,[id, '6a977523d60f46788e6004549027bb8e']) + conn.commit() + cur.close() + conn.close() + print(f'添加查询工单异常记录:{id} 结束') + except Exception as e: + print(f'添加查询工单异常记录:{id}失败, 错误信息:{e}') if __name__ == "__main__": print(f'{formatted2_previous_hour(0)}开始请求工单信息') @@ -189,6 +191,7 @@ if __name__ == "__main__": try: id = data['id'] resD = request_data_signature_get(id) + print(f"请求工单详情结果{resD}") if 'error' in resD: error = resD['error'] print(f"请求工单详情(id:{id})失败,错误信息:{error}") @@ -198,7 +201,7 @@ if __name__ == "__main__": dataList = resL['ticketDetail'] detailDataList.append(dataList) except Exception as e: - print(f'请求工单详情(id:{id})失败, 错误信息:{e}') + print(f'请求工单详情(id:{id})异常, )异常信息:{e}') load_detail_exp_to_db(data['id']) load_detail_data_to_db(ids,detailDataList) print(f'{formatted2_previous_hour(0)}请求工单信息结束') \ No newline at end of file