Browse Source

定时删除系统消息数据接口

locky 11 tháng trước cách đây
mục cha
commit
a24be06a9a
1 tập tin đã thay đổi với 23 bổ sung0 xóa
  1. 23 0
      Controller/Cron/CronTaskController.py

+ 23 - 0
Controller/Cron/CronTaskController.py

@@ -63,6 +63,8 @@ class CronDelDataView(View):
             return self.delPushInfo(response)
         elif operation == 'delPushInfoV2':  # 定时删除推送数据V2
             return self.delPushInfoV2(response)
+        elif operation == 'delSysMsg':  # 定时删除系统消息数据
+            return self.delSysMsg(response)
         elif operation == 'delVodHls':  # 定时删除云存播放列表
             return self.delVodHls(response)
         elif operation == 'delCloudLog':  # 定时删除云存接口数据
@@ -293,6 +295,27 @@ class CronDelDataView(View):
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
+    @staticmethod
+    def delSysMsg(response):
+        try:
+            cursor = connections['mysql02'].cursor()
+
+            # 获取90天前时间戳
+            now_time = int(time.time())
+            expiration_time = LocalDateTimeUtil.get_before_days_timestamp(now_time, 90)
+
+            # 每次删除条数
+            size = 5000
+
+            sql = "DELETE FROM sys_msg WHERE addTime< %s LIMIT %s "
+            cursor.execute(sql, [expiration_time, size])
+
+            # 关闭游标
+            cursor.close()
+            return response.json(0)
+        except Exception as e:
+            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+
     @staticmethod
     def del_push_info_data_v2():
         cursor = connections['mysql02'].cursor()