Add Healthcheck for Linguist colours

This commit is contained in:
Jake Howard 2023-08-19 13:09:26 +01:00
parent 0541f6ce22
commit 6b3f0273a1
Signed by: jake
GPG Key ID: 57AFB45680EDD477
3 changed files with 33 additions and 3 deletions

View File

@ -0,0 +1,11 @@
from django.apps import AppConfig
from health_check.plugins import plugin_dir
class CodeBlockAppConfig(AppConfig):
name = "website.contrib.code_block"
def ready(self) -> None:
from .healthchecks import GitHubLinguistHealthCheckBackend
plugin_dir.register(GitHubLinguistHealthCheckBackend)

View File

@ -0,0 +1,14 @@
from health_check.backends import BaseHealthCheckBackend
from .utils import _get_linguist_colours
class GitHubLinguistHealthCheckBackend(BaseHealthCheckBackend):
def check_status(self) -> None:
colours = _get_linguist_colours()
if colours is None:
self.add_error("No colours provided")
def identifier(self) -> str:
return "GitHub Linguist Colours"

View File

@ -11,9 +11,8 @@ PYGMENTS_VERSION_SLUG = PYGMENTS_VERSION.replace(".", "-")
LINGUIST_DATA_URL = "https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml"
@cache
@django_cache_decorator(time=21600)
def get_linguist_colours() -> dict[str, str]:
@django_cache_decorator(time=600)
def _get_linguist_colours() -> dict[str, str]:
response = requests.get(LINGUIST_DATA_URL)
response.raise_for_status()
@ -25,3 +24,9 @@ def get_linguist_colours() -> dict[str, str]:
for language, data in linguist_data.items()
if data.get("color")
}
@cache
@django_cache_decorator(time=21600)
def get_linguist_colours() -> dict[str, str]:
return _get_linguist_colours()