Bladeren bron

优化邮件提醒uid剩余数量函数

locky 2 jaren geleden
bovenliggende
commit
859c81f185
1 gewijzigde bestanden met toevoegingen van 21 en 17 verwijderingen
  1. 21 17
      Controller/SerialNumberController.py

+ 21 - 17
Controller/SerialNumberController.py

@@ -322,24 +322,28 @@ class SerialNumberView(View):
         # 写入已使用序列号redis列表
         redis_obj.rpush(USED_SERIAL_REDIS_LIST, serial)
 
-        vpg_id = 1
-        if CONFIG_INFO == CONFIG_US:
-            vpg_id = 3
-        elif CONFIG_INFO == CONFIG_EUR:
-            vpg_id = 4
-        p2p_type = int(p2p_type)
+        redis_obj = RedisObject()
+        time_limit_out = redis_obj.CONN.setnx('uid_count_warning', 1)
+        redis_obj.CONN.expire('uid_count_warning', 60*60*24)  # 限制一天提醒一次
+        if time_limit_out:
+            vpg_id = 1
+            if CONFIG_INFO == CONFIG_US:
+                vpg_id = 3
+            elif CONFIG_INFO == CONFIG_EUR:
+                vpg_id = 4
+            p2p_type = int(p2p_type)
 
-        try:
-            # 剩余uid数量少于2000邮件提醒
-            unused_uid_count = UIDModel.objects.filter(vpg_id=vpg_id, p2p_type=p2p_type, status=0).count()
-            LOGGER.info('uid剩余数量:{}'.format(unused_uid_count))
-            warning_count = 2000
-            if unused_uid_count < warning_count:
-                platform = '尚云' if p2p_type == 1 else 'tutk'
-                email_content = '{}服{]的uid数量少于{}个,请及时处理'.format(CONFIG_INFO, platform, warning_count)
-                S3Email().faEmail(email_content, 'servers@ansjer.com')
-        except Exception as e:
-            LOGGER.info('发送提醒邮件异常: error_ine:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            try:
+                # 剩余uid数量少于2000邮件提醒
+                unused_uid_count = UIDModel.objects.filter(vpg_id=vpg_id, p2p_type=p2p_type, status=0).count()
+                LOGGER.info('uid剩余数量:{}'.format(unused_uid_count))
+                warning_count = 2000
+                if unused_uid_count < warning_count:
+                    platform = '尚云' if p2p_type == 1 else 'tutk'
+                    email_content = '{}服{}的uid数量少于{}个,请及时处理'.format(CONFIG_INFO, platform, warning_count)
+                    S3Email().faEmail(email_content, 'servers@ansjer.com')
+            except Exception as e:
+                LOGGER.info('发送提醒邮件异常: error_ine:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
     @staticmethod
     def log_and_send_email(request, company_serial_id, serial, now_time):