Browse Source

更新联通异步统计流量

zhangdongming 2 years ago
parent
commit
f62337772b
2 changed files with 18 additions and 7 deletions
  1. 15 5
      Controller/UnicomCombo/UnicomComboTaskController.py
  2. 3 2
      Object/UnicomObject.py

+ 15 - 5
Controller/UnicomCombo/UnicomComboTaskController.py

@@ -119,10 +119,23 @@ class UnicomComboTaskView(View):
         """
         logger.info('--->进入监控流量使用情况')
         try:
-            unicom_api = UnicomObjeect()
             combo_order_qs = UnicomComboOrderInfo.objects.filter(status=1, is_del=False, combo__is_unlimited=0).values()
             if not combo_order_qs.exists():
                 return response.json(0)
+            asy = threading.Thread(target=UnicomComboTaskView.async_monitoring_flow, args=(combo_order_qs,))
+            asy.start()
+            return response.json(0)
+        except Exception as e:
+            logger.info('出错了~检测流量用量详情异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            return response.json(177, repr(e))
+
+    @classmethod
+    def async_monitoring_flow(cls, combo_order_qs):
+        """
+        异步检测流量使用详情
+        """
+        try:
+            unicom_api = UnicomObjeect()
             today = datetime.datetime.today()
             year = today.year
             month = today.month
@@ -163,11 +176,8 @@ class UnicomComboTaskView(View):
                     if not activate_status:
                         # 停用
                         unicom_api.change_device_to_disable(iccid)
-
-            return response.json(0)
         except Exception as e:
-            logger.info('出错了~检测流量用量详情异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
-            return response.json(177, repr(e))
+            logger.info('异步~检测流量用量详情异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
     @staticmethod
     def flow_warning_push(app_user_id, serial_no, combo_order_id, flow_total, flow_usage):

+ 3 - 2
Object/UnicomObject.py

@@ -232,7 +232,7 @@ class UnicomObjeect:
         return None
 
     @staticmethod
-    def get_flow_total_usage(key, expire=0, **usage_data):
+    def get_flow_total_usage(key, expire=600, **usage_data):
         """
         设备当前队列用量详情(实现缓存)
         @param key: 缓存key
@@ -247,7 +247,8 @@ class UnicomObjeect:
         else:
             flow_usage_details = UnicomObjeect().query_current_renew_list_usage_details(**usage_data)
             flow_usage_details = UnicomObjeect().get_text_dict(flow_usage_details)
-            redis.set_data(key=key, val=json.dumps(flow_usage_details), expire=expire)
+            redis.CONN.setnx(key, json.dumps(flow_usage_details))
+            redis.CONN.expire(key, expire)
         return flow_usage_details
 
     @staticmethod