Don't scream about unready bot on first boot
All checks were successful
Build and Publish Jimmy.2 / build_and_publish (push) Successful in 9s

This commit is contained in:
Nexus 2024-05-04 20:01:37 +01:00
parent d977860cde
commit df453d99a3
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -30,12 +30,13 @@ class KumaThread(KillableThread):
def __init__(self, url: str, interval: float = 60.0): def __init__(self, url: str, interval: float = 60.0):
super().__init__(target=self.run) super().__init__(target=self.run)
self.daemon = True self.daemon = True
self.log = logging.getLogger("philip.status") self.log = logging.getLogger("jimmy .status")
self.url = url self.url = url
self.interval = interval self.interval = interval
self.kill = Event() self.kill = Event()
self.retries = 0 self.retries = 0
self.previous = False self.previous = False
self.was_ready = False
def calculate_backoff(self) -> float: def calculate_backoff(self) -> float:
rnd = random.uniform(0, 1) rnd = random.uniform(0, 1)
@ -55,8 +56,15 @@ class KumaThread(KillableThread):
if url.endswith("ping="): if url.endswith("ping="):
url += str(round(bot.latency * 1000, 2)) url += str(round(bot.latency * 1000, 2))
if bot.is_ready() is False: if bot.is_ready() is False:
if self.was_ready is False:
# Wait rather than attack
self.log.warning("Waiting until bot is initially ready before sending status.")
time.sleep(1)
continue
url = url.replace("status=up", "status=down") url = url.replace("status=up", "status=down")
url = url.replace("msg=OK", "msg=Bot%20not%20ready") url = url.replace("msg=OK", "msg=Bot%20not%20ready")
else:
self.was_ready = True
response = client.get(url) response = client.get(url)
response.raise_for_status() response.raise_for_status()
self.previous = bot.is_ready() self.previous = bot.is_ready()