Parse [database]max_queue_hours as integer, handle invalid format
This commit is contained in:
parent
58a7117bb9
commit
1bec99afaf
1 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue