فهرست منبع

增加 server_const, 增加forward_request
修改接口 get_off_videos.py
response.py

luojunhui 4 ماه پیش
والد
کامیت
4d00464266
2فایلهای تغییر یافته به همراه34 افزوده شده و 14 حذف شده
  1. 29 2
      server/api/get_off_videos.py
  2. 5 12
      server/api/response.py

+ 29 - 2
server/api/get_off_videos.py

@@ -5,6 +5,7 @@ import json
 import time
 
 from applications.log import logging
+from applications.functions.forward_request import forward_requests
 
 
 class GetOffVideos(object):
@@ -87,13 +88,39 @@ class GetOffVideos(object):
                 "msg": "traceId error, can't find trace_id"
             }
 
-    async def deal(self):
+    async def check_trace_id(self):
+        """
+        check trace id 是否存在与系统中
         """
+        select_sql = f"""
+            SELECT trace_id
+            FROM {self.article_match_video_table}
+            WHERE trace_id = '{self.trace_id}';
+            """
+        response = await self.mysql_client.async_select(select_sql)
+        if response:
+            return True
+        else:
+            return False
 
+    async def deal(self):
+        """
         :return:
         """
         params_error = self.check_params()
         if params_error:
             return params_error
         else:
-            return await self.push_video_into_queue()
+            trace_id_exist_flag = await self.check_trace_id()
+            if trace_id_exist_flag:
+                return await self.push_video_into_queue()
+            else:
+                # 只需要传trace_id, 老系统接口不穿strategy参数默认strategy_v1
+                response = await forward_requests(
+                    params={
+                        "traceId": self.trace_id
+                    },
+                    api="get_off_videos"
+                )
+                return response
+

+ 5 - 12
server/api/response.py

@@ -161,13 +161,6 @@ class Response(object):
                 L = []
                 new_item_list = []
                 for index, item in enumerate(response, 1):
-                    # random_num = random.randint(1, 10)
-                    # if random_num in [1, 2, 3, 4, 5, 6]:
-                    #     long_articles_mini_program_id = 25
-                    # elif random_num in [7, 8]:
-                    #     long_articles_mini_program_id = 29
-                    # else:
-                    #     long_articles_mini_program_id = 31
                     card, new_item = await self.generate_single_card(index, gh_id, long_articles_mini_program_id, item)
                     L.append(card)
                     new_item_list.append(new_item)
@@ -199,7 +192,7 @@ class Response(object):
         process_times = response.get('process_times')
         match status_code:
             case 0:
-                if process_times > self.TASK_MAX_PROCESS_TIMES:
+                if process_times > server_const.TASK_MAX_PROCESS_TIMES:
                     result = {
                         "traceId": self.trace_id,
                         "code": 0,
@@ -240,8 +233,8 @@ class Response(object):
                 affected_rows = await self.mysql_client.async_insert(
                     sql=update_sql,
                     params=(
-                        self.REQUEST_PROCESSING_TASK,
-                        self.REQUEST_INIT_STATUS,
+                        server_const.REQUEST_PROCESSING_TASK,
+                        server_const.REQUEST_INIT_STATUS,
                         self.trace_id
                     )
                 )
@@ -261,9 +254,9 @@ class Response(object):
                     sql=update_sql,
                     params=(
                         json.dumps(new_items, ensure_ascii=False),
-                        self.REQUEST_SUCCESS_STATUS,
+                        server_const.REQUEST_SUCCESS_STATUS,
                         self.trace_id,
-                        self.REQUEST_PROCESSING_TASK
+                        server_const.REQUEST_PROCESSING_TASK
                     )
                 )
                 return {