|
@@ -9,16 +9,14 @@ import hashlib
|
|
|
import urllib.parse
|
|
|
|
|
|
from applications.log import logging
|
|
|
+from applications.const import server_const
|
|
|
+from applications.functions.forward_request import forward_requests
|
|
|
|
|
|
|
|
|
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):
|
|
|
"""
|
|
@@ -163,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)
|
|
@@ -201,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,
|
|
@@ -242,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
|
|
|
)
|
|
|
)
|
|
@@ -263,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 {
|
|
@@ -303,6 +294,21 @@ class Response(object):
|
|
|
"message": "该任务正在执行中"
|
|
|
}
|
|
|
|
|
|
+ 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):
|
|
|
"""
|
|
|
api process starts from here
|
|
@@ -312,4 +318,15 @@ 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:
|
|
|
+ response = await forward_requests(
|
|
|
+ params={
|
|
|
+ "traceId": self.trace_id,
|
|
|
+ "miniprogramUseType": self.mini_program_type
|
|
|
+ },
|
|
|
+ api="recall_videos"
|
|
|
+ )
|
|
|
+ return response
|