浏览代码

增加 server_const, 增加forward_request

luojunhui 4 月之前
父节点
当前提交
a906ef6e38

+ 7 - 0
applications/const/__init__.py

@@ -0,0 +1,7 @@
+"""
+@author: luojunhui
+"""
+from .server_const import ServerConst
+
+
+server_const = ServerConst()

+ 29 - 0
applications/const/server_const.py

@@ -0,0 +1,29 @@
+"""
+@author: luojunhui
+"""
+
+
+class ServerConst:
+    """
+    服务常量
+    """
+    # 老服务内外公网 ip
+    OLD_SERVER_PUBLIC_IP = "47.99.132.47"
+    OLD_SERVER_INNER_IP = "192.168.205.85"
+
+    # 新服务内外公网 ip
+    NEW_SERVER_PUBLIC_IP = "47.98.154.124"
+    NEW_SERVER_INNER_IP = "192.168.0.142"
+
+    # 服务端口
+    PORT = "8111"
+
+    # RESPONSE 状态
+    REQUEST_INIT_STATUS = 0
+    REQUEST_SUCCESS_STATUS = 1
+    REQUEST_PROCESSING_TASK = 101
+
+    # 任务最大处理次数
+    TASK_MAX_PROCESS_TIMES = 3
+
+

+ 22 - 0
applications/functions/forward_request.py

@@ -0,0 +1,22 @@
+"""
+@author: luojunhui
+"""
+import requests
+
+from applications.const import server_const
+
+
+async def forward_requests(params, api):
+    """
+    转发请求
+    :return:
+    """
+    new_url = "http://{}:{}/{}".format(server_const.OLD_SERVER_PUBLIC_IP, server_const.PORT, api)
+    response = requests.post(
+        url=new_url,
+        headers={
+            "Content-Type": "application/json",
+        },
+        json=params
+    )
+    return response.json()

+ 11 - 5
server/api/response.py

@@ -9,16 +9,14 @@ import hashlib
 import urllib.parse
 
 from applications.log import logging
+from applications.const import server_const
+from applications.functions import forward_request
 
 
 class Response(object):
     """
     Response
     """
-    REQUEST_INIT_STATUS = 0
-    REQUEST_SUCCESS_STATUS = 1
-    REQUEST_PROCESSING_TASK = 101
-    TASK_MAX_PROCESS_TIMES = 3
 
     def __init__(self, params, mysql_client, config):
         """
@@ -327,4 +325,12 @@ class Response(object):
         if params_error:
             return params_error
         else:
-            return await self.job()
+            trace_id_exist_flag = await self.check_trace_id()
+            if trace_id_exist_flag:
+                return await self.job()
+            else:
+                return {
+                    "traceId": self.trace_id,
+                    "code": 100,
+                    "message": "该 trace_id 不存在"
+                }