Browse Source

2024-06-13
异步定时任务

罗俊辉 1 năm trước cách đây
mục cha
commit
8ac1e4a671
1 tập tin đã thay đổi với 22 bổ sung18 xóa
  1. 22 18
      applications/deal/process_deal.py

+ 22 - 18
applications/deal/process_deal.py

@@ -33,7 +33,10 @@ class ProcessDeal(object):
             LIMIT 4;
             LIMIT 4;
         """
         """
         content_ids = await self.mysql_client.async_select(select_sql1)
         content_ids = await self.mysql_client.async_select(select_sql1)
-        content_ids_tuple = tuple([i[0] for i in content_ids])
+        cil = []
+        for content_id in content_ids:
+            cil.append(content_id[0])
+        content_ids_tuple = str(cil).replace("[", "(").replace("]", ")")
         if len(content_ids_tuple) > 0:
         if len(content_ids_tuple) > 0:
             select_sql = f"""
             select_sql = f"""
                 SELECT trace_id, content_id, gh_id, article_title, article_text, content_status, process_times
                 SELECT trace_id, content_id, gh_id, article_title, article_text, content_status, process_times
@@ -42,6 +45,7 @@ class ProcessDeal(object):
                 ORDER BY request_time_stamp
                 ORDER BY request_time_stamp
                 ASC
                 ASC
             """
             """
+            print(select_sql)
             task_list = await self.mysql_client.async_select(sql=select_sql)
             task_list = await self.mysql_client.async_select(sql=select_sql)
             task_obj_list = [
             task_obj_list = [
                 {
                 {
@@ -282,20 +286,20 @@ class ProcessDeal(object):
         """
         """
         task_list = await self.get_task()
         task_list = await self.get_task()
         # print(task_list)
         # print(task_list)
-        task_dict = {}
-        for task in task_list:
-            key = task['content_id']
-            task_dict[key] = task
-        process_list = []
-        for item in task_dict:
-            process_list.append(task_dict[item])
-        if process_list:
-            # for task in task_list:
-            #     await self.process_task(task)
-            tasks = [self.process_task(params) for params in process_list]
-            await asyncio.gather(*tasks)
-        else:
-            logging(
-                code="9008",
-                info="没有要处理的请求"
-            )
+        # task_dict = {}
+        # for task in task_list:
+        #     key = task['content_id']
+        #     task_dict[key] = task
+        # process_list = []
+        # for item in task_dict:
+        #     process_list.append(task_dict[item])
+        # if process_list:
+        #     # for task in task_list:
+        #     #     await self.process_task(task)
+        #     tasks = [self.process_task(params) for params in process_list]
+        #     await asyncio.gather(*tasks)
+        # else:
+        #     logging(
+        #         code="9008",
+        #         info="没有要处理的请求"
+        #     )