File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,9 @@ def SESSION_COOKIE_SAMESITE(self):
124
124
RTD_ANALYTICS_DEFAULT_RETENTION_DAYS = 30 * 3
125
125
RTD_AUDITLOGS_DEFAULT_RETENTION_DAYS = 30 * 3
126
126
127
+ # Keep BuildData models on database during this time
128
+ RTD_TELEMETRY_DATA_RETENTION_DAYS = 30 * 6 # 180 days / 6 months
129
+
127
130
# Database and API hitting settings
128
131
DONT_HIT_API = False
129
132
DONT_HIT_DB = True
@@ -419,6 +422,11 @@ def TEMPLATES(self):
419
422
'schedule' : crontab (minute = 0 , hour = 1 ),
420
423
'options' : {'queue' : 'web' },
421
424
},
425
+ 'every-day-delete-old-buildata-models' : {
426
+ 'task' : 'readthedocs.telemetry.tasks.delete_old_build_data' ,
427
+ 'schedule' : crontab (minute = 0 , hour = 2 ),
428
+ 'options' : {'queue' : 'web' },
429
+ },
422
430
'every-day-resync-sso-organization-users' : {
423
431
'task' : 'readthedocs.oauth.tasks.sync_remote_repositories_organizations' ,
424
432
'schedule' : crontab (minute = 0 , hour = 4 ),
Original file line number Diff line number Diff line change 1
1
"""Tasks related to telemetry."""
2
2
3
+ from django .conf import settings
4
+ from django .utils import timezone
5
+
3
6
from readthedocs .builds .models import Build
4
7
from readthedocs .telemetry .models import BuildData
5
8
from readthedocs .worker import app
@@ -16,3 +19,18 @@ def save_build_data(build_id, data):
16
19
build = Build .objects .filter (id = build_id ).first ()
17
20
if build :
18
21
BuildData .objects .collect (build , data )
22
+
23
+
24
+ @app .task (queue = "web" )
25
+ def delete_old_build_data ():
26
+ """
27
+ Delete BuildData models older than ``RTD_TELEMETRY_DATA_RETENTION_DAYS``.
28
+
29
+ This is intended to run from a periodic task daily.
30
+
31
+ NOTE: the logic of this task could be improved to keep longer data we care
32
+ more (eg. active projects )and remove data we don't (eg. builds from spam projects)
33
+ """
34
+ retention_days = settings .RTD_TELEMETRY_DATA_RETENTION_DAYS
35
+ days_ago = timezone .now ().date () - timezone .timedelta (days = retention_days )
36
+ return BuildData .objects .filter (created__lt = days_ago ).delete ()
You can’t perform that action at this time.
0 commit comments