Cleanup: use max of last update and start time to determine expiry time
This commit is contained in:
@@ -8,12 +8,13 @@ from .models import Hostname, User
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
def cleanup_expired(app):
|
||||
def cleanup_expired(app, start_time=None):
|
||||
"""
|
||||
Clean up expired hostnames and return count of cleaned entries.
|
||||
|
||||
Args:
|
||||
app: Application instance with dns_service and email_service.
|
||||
start_time: Timezone aware datetime object containg the start time of the cleanup thread.
|
||||
|
||||
Returns:
|
||||
Number of expired hostnames processed.
|
||||
@@ -30,12 +31,14 @@ def cleanup_expired(app):
|
||||
ipv6_expired = False
|
||||
|
||||
if hostname.last_ipv4:
|
||||
expiry_time = hostname.last_ipv4_update + timedelta(seconds=hostname.expiry_ttl)
|
||||
last_update = max(hostname.last_ipv4_update, start_time)
|
||||
expiry_time = last_update + timedelta(seconds=hostname.expiry_ttl)
|
||||
if now > expiry_time:
|
||||
ipv4_expired = True
|
||||
|
||||
if hostname.last_ipv6:
|
||||
expiry_time = hostname.last_ipv6_update + timedelta(seconds=hostname.expiry_ttl)
|
||||
last_update = max(hostname.last_ipv6_update, start_time)
|
||||
expiry_time = last_update + timedelta(seconds=hostname.expiry_ttl)
|
||||
if now > expiry_time:
|
||||
ipv6_expired = True
|
||||
|
||||
@@ -117,10 +120,11 @@ class ExpiredRecordsCleanupThread(threading.Thread):
|
||||
def run(self):
|
||||
"""Run the cleanup loop."""
|
||||
logging.info(f"Expired records cleanup thread started: interval={self.interval}s")
|
||||
start_time = now_utc()
|
||||
|
||||
while not self.stop_event.wait(self.interval):
|
||||
try:
|
||||
count = cleanup_expired(self.app)
|
||||
count = cleanup_expired(self.app, start_time)
|
||||
if count > 0:
|
||||
logging.info(f"Expired records cleanup completed: count={count}")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user