diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 1f65c884..98c8c37e 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -162,7 +162,7 @@ class Sf_Dashboard_Connect(http.Controller): # 关机时长:初次上线时间 - 通电时间 'power_off_time': power_off_time, # 关机率:关机时长/初次上线时间 - 'power_off_rate': power_off_rate, + # 'power_off_rate': power_off_rate, 'first_online_duration': first_online_duration, # 停机时间:关机时间 - 运行时间 # 停机时长:关机时间 - 初次上线时间 @@ -187,11 +187,11 @@ class Sf_Dashboard_Connect(http.Controller): """ res = {'status': 1, 'message': '成功', 'data': {}} logging.info('前端请求日志数据的参数为:%s' % kw) + # 连接数据库 + conn = psycopg2.connect(**db_config) + cur = conn.cursor() try: - # 连接数据库 - conn = psycopg2.connect(**db_config) - cur = conn.cursor() machine_list = ast.literal_eval(kw['machine_list']) begin_time_str = kw['begin_time'].strip('"') end_time_str = kw['end_time'].strip('"') @@ -231,6 +231,12 @@ class Sf_Dashboard_Connect(http.Controller): res['message'] = '前端请求日志数据失败,原因:%s' % e return json.dumps(res) + finally: + if cur: + cur.close() + if conn: + conn.close() + @http.route('/api/logs/page_data', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") def logs_page_data(self, **kw): @@ -242,11 +248,10 @@ class Sf_Dashboard_Connect(http.Controller): res = {'status': 1, 'message': '成功', 'data': {}} logging.info('前端请求日志数据的参数为:%s' % kw) + # 连接数据库 + conn = psycopg2.connect(**db_config) + cur = conn.cursor() try: - # 连接数据库 - conn = psycopg2.connect(**db_config) - cur = conn.cursor() - # 获取并解析传递的参数 machine_list = ast.literal_eval(kw.get('machine_list', '[]')) begin_time_str = kw.get('begin_time', '').strip('"')