|
@@ -8,6 +8,7 @@
|
|
|
# @File : CronTaskController.py
|
|
|
# @Software: PyCharm
|
|
|
import datetime
|
|
|
+import threading
|
|
|
import time
|
|
|
|
|
|
import requests
|
|
@@ -1259,10 +1260,18 @@ class CronCollectDataView(View):
|
|
|
@staticmethod
|
|
|
def collect_flow_info(response):
|
|
|
try:
|
|
|
- redis_obj = RedisObject()
|
|
|
unicom_qs = UnicomComboOrderInfo.objects.filter(combo__combo_type__in=[0, 1, 2]).values('iccid')
|
|
|
+ asy = threading.Thread(target=CronCollectDataView.thread_collect_flow, args=(unicom_qs))
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def thread_collect_flow(qs):
|
|
|
+ try:
|
|
|
unicom_api = UnicomObjeect()
|
|
|
- for item in unicom_qs:
|
|
|
+ redis_obj = RedisObject()
|
|
|
+ for item in qs:
|
|
|
res = unicom_api.query_device_usage_history(**item)
|
|
|
if res.status_code == 200:
|
|
|
res_json = res.json()
|
|
@@ -1279,6 +1288,5 @@ class CronCollectDataView(View):
|
|
|
key = 'monthly' + item['iccid']
|
|
|
if redis_dict:
|
|
|
redis_obj.set_hash_data(key, redis_dict)
|
|
|
- return response.json(0)
|
|
|
except Exception as e:
|
|
|
- return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ LOGGER.info('统计联通流量失败,时间为:{}'.format(int(time.time())))
|