Browse Source

修复定时删除接口存在问题

locky 3 years ago
parent
commit
852bd8652a
2 changed files with 11 additions and 3 deletions
  1. 2 3
      Controller/Cron/CronTaskController.py
  2. 9 0
      Object/utils/LocalDateTimeUtil.py

+ 2 - 3
Controller/Cron/CronTaskController.py

@@ -52,10 +52,9 @@ class CronDelDataView(View):
         try:
             cursor = connection.cursor()
             # 删除7天前的数据
-            now_time = int(time.time())
-            last_month = LocalDateTimeUtil.get_before_days_timestamp(now_time, 7)
+            last_week = LocalDateTimeUtil.get_last_week()
             sql = 'DELETE FROM access_log WHERE time < %s limit %s'
-            cursor.execute(sql, [last_month, 10000])
+            cursor.execute(sql, [last_week, 10000])
             # 关闭游标
             cursor.close()
             connection.close()

+ 9 - 0
Object/utils/LocalDateTimeUtil.py

@@ -152,6 +152,15 @@ def get_today_date(timestamp=False):
         return zero_today, last_today
     return zero_today, last_today
 
+def get_last_week():
+    """
+    获取前一周时间
+    @return: last_week_date
+    """
+    today = datetime.date.today()  # 1. 获取「今天」
+    last_week = today - datetime.timedelta(days=7)  # 2.获取7天前
+    last_week_date = last_week.strftime("%Y-%m-%d %H:%M:%S")
+    return last_week_date
 
 def get_last_month():
     """