1414import requests
1515
1616from 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
1818from lookup import PROTOCOLS , DIRECTION_INGRESS , DIRECTION_EGRESS
1919
2020logging .basicConfig (format = '%(asctime)s.%(msecs)03d | %(levelname)s | %(message)s' ,
@@ -77,10 +77,9 @@ def _save_current_max_ts(job_id, max_ts):
7777
7878
7979def job_maint_remove_old_partitions (* args , ** kwargs ):
80- LEAVE_N_PAST_DAYS = 5
8180 with get_db_cursor () as c :
8281 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 )
8483 c .execute (f"SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename LIKE '{ DB_PREFIX } flows_%';" )
8584 for tablename , in c .fetchall ():
8685 m = re .match (f'^{ DB_PREFIX } flows_([0-9]+)$' , tablename )
@@ -91,7 +90,7 @@ def job_maint_remove_old_partitions(*args, **kwargs):
9190 if day_seq > today_seq :
9291 log .warning (f"MAINT: CAREFUL! Table { tablename } marks a future day (today is { today_seq } ); this should never happen! Skipping." )
9392 continue
94- if day_seq < today_seq - LEAVE_N_PAST_DAYS :
93+ if day_seq < today_seq - LEAVE_N_PAST_PARTITIONS :
9594 log .info (f"MAINT: Removing old data: { tablename } (today is { today_seq } )" )
9695 c .execute (f"DROP TABLE { tablename } ;" )
9796 else :
0 commit comments