-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added extension for Hyperping health check support
- Loading branch information
1 parent
deb39b8
commit e893ae7
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
""" | ||
Extension to report pings to Hyperping. | ||
""" | ||
|
||
from .hyperping import Hyperping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |