Improve error handling during cleanup
This commit is contained in:
@@ -42,20 +42,37 @@ def cleanup_expired(app):
|
|||||||
if not ipv4_expired and not ipv6_expired:
|
if not ipv4_expired and not ipv6_expired:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
ipv4_deleted = False
|
||||||
|
ipv6_deleted = False
|
||||||
|
|
||||||
if app.dns_service:
|
if app.dns_service:
|
||||||
if ipv4_expired:
|
if ipv4_expired:
|
||||||
logging.info(
|
logging.info(
|
||||||
f"Host expired: hostname={hostname.hostname} zone={hostname.zone} "
|
f"Host expired: hostname={hostname.hostname} zone={hostname.zone} "
|
||||||
f"ip={hostname.last_ipv4}"
|
f"ip={hostname.last_ipv4}"
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
app.dns_service.delete_record(hostname.hostname, hostname.zone, "A")
|
app.dns_service.delete_record(hostname.hostname, hostname.zone, "A")
|
||||||
|
ipv4_deleted = True
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(
|
||||||
|
f"DNS delete failed: hostname={hostname.hostname} "
|
||||||
|
f"zone={hostname.zone} type=A error={e}"
|
||||||
|
)
|
||||||
|
|
||||||
if ipv6_expired:
|
if ipv6_expired:
|
||||||
logging.info(
|
logging.info(
|
||||||
f"Host expired: hostname={hostname.hostname} zone={hostname.zone} "
|
f"Host expired: hostname={hostname.hostname} zone={hostname.zone} "
|
||||||
f"ip={hostname.last_ipv6}"
|
f"ip={hostname.last_ipv6}"
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
app.dns_service.delete_record(hostname.hostname, hostname.zone, "AAAA")
|
app.dns_service.delete_record(hostname.hostname, hostname.zone, "AAAA")
|
||||||
|
ipv6_deleted = True
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(
|
||||||
|
f"DNS delete failed: hostname={hostname.hostname} "
|
||||||
|
f"zone={hostname.zone} type=AAAA error={e}"
|
||||||
|
)
|
||||||
|
|
||||||
if app.email_service:
|
if app.email_service:
|
||||||
app.email_service.send_expiry_notification(
|
app.email_service.send_expiry_notification(
|
||||||
@@ -65,15 +82,14 @@ def cleanup_expired(app):
|
|||||||
ipv6_expired
|
ipv6_expired
|
||||||
)
|
)
|
||||||
|
|
||||||
# Clear IP addresses
|
# Clear IP addresses only if DNS delete succeeded
|
||||||
if ipv4_expired:
|
if ipv4_deleted:
|
||||||
hostname.last_ipv4 = None
|
hostname.last_ipv4 = None
|
||||||
if ipv6_expired:
|
if ipv6_deleted:
|
||||||
hostname.last_ipv6 = None
|
hostname.last_ipv6 = None
|
||||||
|
|
||||||
if ipv4_expired or ipv6_expired:
|
if ipv4_deleted or ipv6_deleted:
|
||||||
hostname.save()
|
hostname.save()
|
||||||
|
|
||||||
expired_count += 1
|
expired_count += 1
|
||||||
|
|
||||||
return expired_count
|
return expired_count
|
||||||
|
|||||||
Reference in New Issue
Block a user