Skip to content

Commit

Permalink
Merge pull request #288 from hamza1312/hamza_changes
Browse files Browse the repository at this point in the history
K8s health check
  • Loading branch information
SylteA authored Dec 6, 2023
2 parents 57c3788 + cecd51a commit 17083e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from bot.services import http, paste
from bot.services.paste import Document
from utils.errors import IgnorableException
from utils.health import update_health
from utils.time import human_timedelta

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -52,10 +53,18 @@ async def setup_hook(self) -> None:
self.loop.create_task(self.when_online())
self.presence.start()

update_health("running", True)

self.tree.on_error = self.on_app_command_error

self.error_webhook = discord.Webhook.from_url(url=settings.errors.webhook_url, session=http.session)

async def on_disconnect(self):
update_health("ready", False)

async def on_ready(self):
update_health("ready", True)

async def when_online(self):
log.info("Waiting until bot is ready to load extensions and app commands.")
await self.wait_until_ready()
Expand Down
11 changes: 11 additions & 0 deletions utils/health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os


def update_health(name: str, value: bool):
path = f"/tmp/.health.{name.lower()}"

with open(path, "w") as f:
f.write(str(value))
# checking after to avoid making sure the file exists
if not value:
os.remove(path)

0 comments on commit 17083e0

Please sign in to comment.