From 0541f6ce2241dbfd0c013f1ebf9299f793ff7916 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 19 Aug 2023 13:00:01 +0100 Subject: [PATCH] Add healthcheck for Spotify proxy --- website/spotify/apps.py | 11 +++++++++++ website/spotify/healthchecks.py | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 website/spotify/apps.py create mode 100644 website/spotify/healthchecks.py diff --git a/website/spotify/apps.py b/website/spotify/apps.py new file mode 100644 index 0000000..b0d70c6 --- /dev/null +++ b/website/spotify/apps.py @@ -0,0 +1,11 @@ +from django.apps import AppConfig +from health_check.plugins import plugin_dir + + +class SpotifyAppConfig(AppConfig): + name = "website.spotify" + + def ready(self) -> None: + from .healthchecks import SpotifyHealthCheckBackend + + plugin_dir.register(SpotifyHealthCheckBackend) diff --git a/website/spotify/healthchecks.py b/website/spotify/healthchecks.py new file mode 100644 index 0000000..937c928 --- /dev/null +++ b/website/spotify/healthchecks.py @@ -0,0 +1,13 @@ +import requests +from django.conf import settings +from health_check.backends import BaseHealthCheckBackend + + +class SpotifyHealthCheckBackend(BaseHealthCheckBackend): + def check_status(self) -> None: + requests.get( + f"https://{settings.SPOTIFY_PROXY_HOST}/.health/" + ).raise_for_status() + + def identifier(self) -> str: + return "Spotify Proxy"