Przeglądaj źródła

多线程发起请求

locky 11 miesięcy temu
rodzic
commit
aac7c9f64c
1 zmienionych plików z 12 dodań i 9 usunięć
  1. 12 9
      Controller/Cron/CronTaskController.py

+ 12 - 9
Controller/Cron/CronTaskController.py

@@ -1348,8 +1348,8 @@ class CronCollectDataView(View):
             print('error')
             LOGGER.info('统计s3信息异常:errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
-    @staticmethod
-    def check_request(response):
+    @classmethod
+    def check_request(cls, response):
         domain_name_list = [
             'test.zositechc.cn', 'test.push.zositechc.cn',
             'www.zositechc.cn', 'api.loocam2.cn', 'common.neutral2.cn', 'api.aiotserver.cn', 'push.zositechc.cn',
@@ -1360,15 +1360,18 @@ class CronCollectDataView(View):
             'www.zositech.xyz', 'smart.loocam2.com'
         ]
         for domain_name in domain_name_list:
-            url = 'https://{}/init/health-check'.format(domain_name)
-            try:
-                requests.post(url=url, timeout=30)
-            except Exception as e:
-                email_content = 'https请求域名{}出现异常!error_msg:{}'.format(domain_name, repr(e))
-                S3Email().faEmail(email_content, 'servers@ansjer.com')
+            thread = threading.Thread(target=cls.initial_request, args=(domain_name,))
+            thread.start()
         return response.json(0)
 
-
+    @staticmethod
+    def initial_request(domain_name):
+        url = 'https://{}/init/health-check'.format(domain_name)
+        try:
+            requests.post(url=url, timeout=30)
+        except Exception as e:
+            email_content = 'https请求域名{}出现异常!error_msg:{}'.format(domain_name, repr(e))
+            S3Email().faEmail(email_content, 'servers@ansjer.com')
 
     @staticmethod
     def collect_icloud_order(response):