You've already forked Promocode-API
mirror of
https://github.com/devitq/Promocode-API.git
synced 2026-05-22 22:07:12 +00:00
feat: added antifraud healthcheck
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
from http import HTTPStatus as status
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
from django.conf import settings
|
||||||
|
from health_check.backends import BaseHealthCheckBackend
|
||||||
|
|
||||||
|
|
||||||
|
class AntifraudHealthcheck(BaseHealthCheckBackend):
|
||||||
|
critical_service = False
|
||||||
|
|
||||||
|
def check_status(self) -> None:
|
||||||
|
try:
|
||||||
|
response = httpx.get(f"{settings.ANTIFRAUD_ENDPOINT}/api/ping")
|
||||||
|
if response.status_code >= status.INTERNAL_SERVER_ERROR:
|
||||||
|
self.add_error("Antifraud service is unaccessible")
|
||||||
|
except httpx.HTTPError:
|
||||||
|
self.add_error("Antifraud service is unaccessible")
|
||||||
|
|
||||||
|
def identifier(self) -> str:
|
||||||
|
return self.__class__.__name__
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["AntifraudHealthcheck"]
|
||||||
@@ -5,6 +5,9 @@ from pathlib import Path
|
|||||||
|
|
||||||
import environ
|
import environ
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from health_check.plugins import plugin_dir
|
||||||
|
|
||||||
|
from config.integrations.antifraud.healthcheck import AntifraudHealthcheck
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
@@ -25,7 +28,13 @@ ALLOWED_HOSTS = env(
|
|||||||
|
|
||||||
# Integrations
|
# Integrations
|
||||||
|
|
||||||
ANTIFRAUD_ADDRESS = env("ANTIFRAUD_ADDRESS", default="localhost:9090")
|
ANTIFRAUD_ENDPOINT = (
|
||||||
|
f"http://{env('ANTIFRAUD_ADDRESS', default='http://localhost:9090')}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Register healthcheck
|
||||||
|
|
||||||
|
plugin_dir.register(AntifraudHealthcheck)
|
||||||
|
|
||||||
|
|
||||||
# Caching
|
# Caching
|
||||||
|
|||||||
Reference in New Issue
Block a user