CronDelDataController.py 865 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/python3.6
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2022 #
  5. # @Time : 2022/4/1 11:27
  6. # @Author : ming
  7. # @Email : zhangdongming@asj6.wecom.work
  8. # @File : CronDelDataController.py
  9. # @Software: PyCharm
  10. from django.db import connection
  11. from Object.ResponseObject import ResponseObject
  12. from Object.utils import LocalDateTimeUtil
  13. def deleteExpireAccessLog(request):
  14. response = ResponseObject()
  15. try:
  16. print(request)
  17. cursor = connection.cursor()
  18. # 删除一个月前的数据
  19. last_month = LocalDateTimeUtil.get_last_month()
  20. sql = 'DELETE FROM access_log WHERE time < %s limit %s'
  21. cursor.execute(sql, [last_month, 10000])
  22. # 关闭游标
  23. cursor.close()
  24. connection.close()
  25. return response.json(0)
  26. except Exception as e:
  27. return response.json(500, repr(e))