14
14
import requests
15
15
16
16
from grafoleancollector import Collector , send_results_to_grafolean
17
- from dbutils import get_db_cursor , DB_PREFIX
17
+ from dbutils import get_db_cursor , DB_PREFIX , S_PER_PARTITION , LEAVE_N_PAST_PARTITIONS
18
18
from lookup import PROTOCOLS , DIRECTION_INGRESS , DIRECTION_EGRESS
19
19
20
20
logging .basicConfig (format = '%(asctime)s.%(msecs)03d | %(levelname)s | %(message)s' ,
@@ -77,10 +77,9 @@ def _save_current_max_ts(job_id, max_ts):
77
77
78
78
79
79
def job_maint_remove_old_partitions (* args , ** kwargs ):
80
- LEAVE_N_PAST_DAYS = 5
81
80
with get_db_cursor () as c :
82
81
log .info ("MAINT: Maintenance started - removing old partitions" )
83
- today_seq = int (time .time () // ( 24 * 3600 ) )
82
+ today_seq = int (time .time () // S_PER_PARTITION )
84
83
c .execute (f"SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename LIKE '{ DB_PREFIX } flows_%';" )
85
84
for tablename , in c .fetchall ():
86
85
m = re .match (f'^{ DB_PREFIX } flows_([0-9]+)$' , tablename )
@@ -91,7 +90,7 @@ def job_maint_remove_old_partitions(*args, **kwargs):
91
90
if day_seq > today_seq :
92
91
log .warning (f"MAINT: CAREFUL! Table { tablename } marks a future day (today is { today_seq } ); this should never happen! Skipping." )
93
92
continue
94
- if day_seq < today_seq - LEAVE_N_PAST_DAYS :
93
+ if day_seq < today_seq - LEAVE_N_PAST_PARTITIONS :
95
94
log .info (f"MAINT: Removing old data: { tablename } (today is { today_seq } )" )
96
95
c .execute (f"DROP TABLE { tablename } ;" )
97
96
else :
0 commit comments