chg: retry a few times if remote lacus isn't available immediately

pull/723/head
Raphaël Vinot 2023-06-16 12:47:50 +02:00
parent 62ec2e74cd
commit 475b424878
1 changed files with 12 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import logging
import operator import operator
import smtplib import smtplib
import ssl import ssl
import time
from collections import defaultdict from collections import defaultdict
from datetime import date, datetime, timezone from datetime import date, datetime, timezone
@ -168,13 +169,18 @@ class Lookyloo():
remote_lacus_config = get_config('generic', 'remote_lacus') remote_lacus_config = get_config('generic', 'remote_lacus')
if remote_lacus_config.get('enable'): if remote_lacus_config.get('enable'):
self.logger.info("Remote lacus enabled, trying to set it up...") self.logger.info("Remote lacus enabled, trying to set it up...")
remote_lacus_url = remote_lacus_config.get('url') lacus_retries = 10
self._lacus = PyLacus(remote_lacus_url) while lacus_retries > 0:
if self._lacus.is_up: remote_lacus_url = remote_lacus_config.get('url')
has_remote_lacus = True self._lacus = PyLacus(remote_lacus_url)
self.logger.info(f"Remote lacus enabled to {remote_lacus_url}.") if self._lacus.is_up:
has_remote_lacus = True
self.logger.info(f"Remote lacus enabled to {remote_lacus_url}.")
break
lacus_retries -= 1
self.logger.warning(f"Unable to setup remote lacus to {remote_lacus_url}, trying again {lacus_retries} more time(s).")
time.sleep(10)
else: else:
self.logger.warning(f"Unable to setup remote lacus to {remote_lacus_url}.")
raise LookylooException('Remote lacus is enabled but unreachable.') raise LookylooException('Remote lacus is enabled but unreachable.')
if not has_remote_lacus: if not has_remote_lacus: