Merge pull request 'Parse [database]max_queue_hours as integer, handle invalid format' (#155) from bugfix/key-queue-ttl into develop

Reviewed-on: #155
Reviewed-by: muppeth <muppeth@no-reply@disroot.org>
This commit is contained in:
pfm 2024-08-27 21:13:10 +02:00
commit 64b401fb66

View file

@ -5,6 +5,10 @@ from datetime import datetime, timedelta
from lacre.config import get_item
# By default, we let keys stay in confirmation queue for 1 hour.
_DEFAULT_TTL = 1
def calculate_expiry_date(now: datetime) -> datetime:
"""Calculate date-time of key queue item expiry.
@ -12,5 +16,15 @@ def calculate_expiry_date(now: datetime) -> datetime:
[database]max_queue_hours, return a date-time object that should be
older than any key in our confirmation queue. If a key is older
than this threshold, we should remove it."""
max_hours = get_item('database', 'max_queue_hours', 1)
max_hours = _get_ttl()
return now - timedelta(hours=max_hours)
def _get_ttl():
max_hours = get_item('database', 'max_queue_hours', _DEFAULT_TTL)
try:
ttl = int(max_hours)
return ttl
except ValueError:
# Not a valid integer, so we return the default.
return _DEFAULT_TTL