-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgc.py
34 lines (26 loc) · 834 Bytes
/
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
import sys
import kv_manager
from core import maand_data, utils
logger = utils.get_logger()
def clean_agents(cursor):
cursor.execute(
"DELETE FROM agent_labels WHERE agent_id IN (SELECT agent_id FROM agent WHERE detained = 1)"
)
cursor.execute(
"DELETE FROM agent_tags WHERE agent_id IN (SELECT agent_id FROM agent WHERE detained = 1)"
)
cursor.execute("DELETE FROM agent_jobs WHERE removed = 1")
cursor.execute("DELETE FROM agent WHERE detained = 1")
def clean():
with maand_data.get_db() as db:
cursor = db.cursor()
try:
clean_agents(cursor)
kv_manager.gc(cursor, -1)
db.commit()
except Exception as e:
db.rollback()
logger.fatal(e)
sys.exit(1)
if __name__ == "__main__":
clean()