Skip to content

Commit

Permalink
Added extension for Hyperping health check support
Browse files Browse the repository at this point in the history
  • Loading branch information
justalemon committed Mar 5, 2024
1 parent deb39b8 commit e893ae7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions leek/hyperping/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
Extension to report pings to Hyperping.
"""

from .hyperping import Hyperping
52 changes: 52 additions & 0 deletions leek/hyperping/hyperping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Extension to report pings to Hyperping.
"""

import logging
import os

from discord.ext import tasks
from discord.ext.commands import Cog

from leek import LeekBot

LOGGER = logging.getLogger("leek_hyperping")


class Hyperping(Cog):
"""
Cog used to report pings to Hyperping.
"""
def __init__(self, bot: LeekBot):
"""
Creates a new Cog.
"""
self.bot = bot
self.url = os.environ.get("HYPERPING_URL", None)

if self.url is None:
LOGGER.error("No Hyperping URL specified, no Pings will be sent!")

self.ping.start()

async def send_ping(self) -> bool:
"""
Sends a ping to Hyperping.
"""
if self.url is None:
return False

async with await self.bot.head(self.url) as resp:
return resp.ok

@tasks.loop(seconds=float(os.environ.get("HYPERPING_DELAY", 60.0)))
async def ping(self) -> None:
"""
Sends the ping every couple of seconds.
"""
success = await self.send_ping()

if success:
LOGGER.info("Successful report to Hyperping")
else:
LOGGER.error("Unable to report to Hyperping, check Hyperping for more information")

0 comments on commit e893ae7

Please sign in to comment.