-
Notifications
You must be signed in to change notification settings - Fork 9
/
cfbot_gc.py
57 lines (50 loc) · 1.81 KB
/
cfbot_gc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
import cfbot_util
def macro_gc(conn):
cursor = conn.cursor()
cursor.execute("""set work_mem = '256MB'""")
#cursor.execute("""set max_parallel_workers_per_gather = 0""")
# XXX figure out the order to delete old stuff like this in
#cursor.execute("""DELETE FROM task WHERE created < now() - interval '6 months'""")
#cursor.execute("""DELETE FROM branch WHERE created < now() - interval '6 months'""")
#cursor.execute("""UPDATE branch SET status = 'timeout' WHERE created < now() - interval '2 hours' AND status = 'testing'""")
# TODO: GC the git tree too!
# delete old artifact bodies due to lack of disk space
cursor.execute("""
update artifact
set body = null
from task
where artifact.task_id = task.task_id
and artifact.body is not null
and task.created < now() - interval '2 days'
""")
conn.commit()
# likewise for task_command logs
cursor.execute("""
update task_command
set log = null
from task
where task_command.task_id = task.task_id
and task_command.log is not null
and task.created < now() - interval '2 days'
""")
# likewise for everything derived from old tasks
cursor.execute("""
delete from artifact
where task_id in (select task_id
from task
where created < now() - interval '90 days')""")
cursor.execute("""
delete from test
where task_id in (select task_id
from task
where created < now() - interval '90 days')""")
cursor.execute("""
delete from task_command
where task_id in (select task_id
from task
where created < now() - interval '90 days')""")
conn.commit()
if __name__ == "__main__":
with cfbot_util.db() as conn:
macro_gc(conn)