File tree 2 files changed +34
-0
lines changed 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ import logging
2
+
3
+ from django .conf import settings
4
+ from django .utils import timezone
5
+
6
+ from readthedocs .audit .models import AuditLog
7
+ from readthedocs .worker import app
8
+
9
+ log = logging .getLogger (__name__ )
10
+
11
+
12
+ @app .task (queue = 'web' )
13
+ def delete_old_personal_audit_logs (days = None ):
14
+ """
15
+ Delete audit logs from related to users older the `days`.
16
+
17
+ We only delete logs related to users,
18
+ logs related to an organization are ignored here.
19
+ There are tasks com .com to delete those according to their plan.
20
+ """
21
+ days = days or settings .RTD_AUDITLOGS_DEFAULT_RETENTION_DAYS
22
+ days_ago = timezone .now () - timezone .timedelta (days = days )
23
+ audit_logs = AuditLog .objects .filter (
24
+ log_user_id__isnull = False ,
25
+ log_organization_id__isnull = True ,
26
+ created__lt = days_ago ,
27
+ )
28
+ log .info ("Deleting old audit logs from users. days=%s logs=%s" , days , audit_logs .count ())
29
+ audit_logs .delete ()
Original file line number Diff line number Diff line change @@ -422,6 +422,11 @@ def TEMPLATES(self):
422
422
'schedule' : crontab (minute = 0 , hour = 1 ),
423
423
'options' : {'queue' : 'web' },
424
424
},
425
+ 'every-week-delete-old-personal-audit-logs' : {
426
+ 'task' : 'readthedocs.audi.tasks.delete_old_personal_audit_logs' ,
427
+ 'schedule' : crontab (day_of_week = 'wednesday' , hour = 7 , minute = 0 ),
428
+ 'options' : {'queue' : 'web' },
429
+ },
425
430
'every-day-resync-sso-organization-users' : {
426
431
'task' : 'readthedocs.oauth.tasks.sync_remote_repositories_organizations' ,
427
432
'schedule' : crontab (minute = 0 , hour = 4 ),
You can’t perform that action at this time.
0 commit comments