Add unsplash healthcheck
This commit is contained in:
parent
6b3f0273a1
commit
e870f4b162
2 changed files with 31 additions and 0 deletions
11
website/contrib/unsplash/apps.py
Normal file
11
website/contrib/unsplash/apps.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from django.apps import AppConfig
|
||||
from health_check.plugins import plugin_dir
|
||||
|
||||
|
||||
class UnsplashAppConfig(AppConfig):
|
||||
name = "website.contrib.unsplash"
|
||||
|
||||
def ready(self) -> None:
|
||||
from .healthchecks import UnsplashHealthCheckBackend
|
||||
|
||||
plugin_dir.register(UnsplashHealthCheckBackend)
|
20
website/contrib/unsplash/healthchecks.py
Normal file
20
website/contrib/unsplash/healthchecks.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import requests
|
||||
from django.conf import settings
|
||||
from health_check.backends import BaseHealthCheckBackend
|
||||
|
||||
|
||||
class UnsplashHealthCheckBackend(BaseHealthCheckBackend):
|
||||
def check_status(self) -> None:
|
||||
try:
|
||||
requests.get(
|
||||
"https://api.unsplash.com/me",
|
||||
headers={
|
||||
"Accept-Version": "v1",
|
||||
"Authorization": f"Client-ID {settings.UNSPLASH_CLIENT_ID}",
|
||||
},
|
||||
).raise_for_status()
|
||||
except Exception as e:
|
||||
self.add_error(str(e))
|
||||
|
||||
def identifier(self) -> str:
|
||||
return "Unsplash API"
|
Loading…
Reference in a new issue