Explorar el Código

线程池关闭旧数据库连接

zhangdongming hace 1 año
padre
commit
f39bdca4f4
Se han modificado 1 ficheros con 5 adiciones y 3 borrados
  1. 5 3
      Service/DevicePushService.py

+ 5 - 3
Service/DevicePushService.py

@@ -35,6 +35,7 @@ from Service.CommonService import CommonService
 from Service.EquipmentInfoService import EquipmentInfoService, EQUIPMENT_INFO_DICT
 from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
 from Service.PushService import PushObject
+from django.db import close_old_connections
 
 LOGGING = logging.getLogger('info')
 TIME_LOGGER = logging.getLogger('time')
@@ -280,7 +281,7 @@ class DevicePushService:
                         redis_obj.rpush(equipment_info_key, equipment_info_value)
                         LOGGING.info('***保存推送消息uid:{},time:{},user_id:{}'.format(uid, params['n_time'], user_id))
                     saved_user_id_list.append(user_id)
-
+            close_old_connections()
             # 写入系统消息
             if sys_msg_list:
                 SysMsgModel.objects.bulk_create(sys_msg_list)
@@ -315,7 +316,7 @@ class DevicePushService:
                         equipment_info_model.objects.bulk_create(equipment_info_list)
             return True
         except Exception as e:
-            LOGGING.info('推送消息或存表异常uid{}: error_line:{}, error_msg:{}'.format(uid, e.__traceback__.tb_lineno, repr(e)))
+            LOGGING.info('推送消息或存表异常uid:{}, error_line:{}, error_msg:{}'.format(uid, e.__traceback__.tb_lineno, repr(e)))
             return False
 
     @classmethod
@@ -825,7 +826,8 @@ class DevicePushService:
                 params['Key'] = key_name
                 if kwargs['region'] == 1:
                     # OCI
-                    img_url = DevicePushService.create_oci_req_url(storage_location, params['Bucket'], key_name, oci_client)
+                    img_url = DevicePushService.create_oci_req_url(storage_location, params['Bucket'], key_name,
+                                                                   oci_client)
                     img_url_list.append(img_url)
                 else:
                     # 华为云