From c073cb0b3afc0ddf0ef4b46c9bc650b2d7e2a1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 27 Mar 2017 11:18:08 +0100 Subject: [PATCH] Lightweight 'server status' API endpoint, to be used by external load balancers --- hc/api/urls.py | 1 + hc/api/views.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/hc/api/urls.py b/hc/api/urls.py index d726802f..da2a6874 100644 --- a/hc/api/urls.py +++ b/hc/api/urls.py @@ -12,4 +12,5 @@ urlpatterns = [ name="hc-api-bounce"), url(r'^badge/([\w-]+)/([\w-]{8})/([\w-]+).svg$', views.badge, name="hc-badge"), + url(r'^api/v1/status/$', views.status), ] diff --git a/hc/api/views.py b/hc/api/views.py index 63ad58d1..177016c2 100644 --- a/hc/api/views.py +++ b/hc/api/views.py @@ -1,5 +1,6 @@ from datetime import timedelta as td +from django.db import connection from django.db.models import F from django.http import (HttpResponse, HttpResponseForbidden, HttpResponseNotFound, JsonResponse) @@ -185,3 +186,11 @@ def bounce(request, code): notification.save() return HttpResponse() + + +def status(request): + with connection.cursor() as c: + c.execute("SELECT 1") + c.fetchone() + + return HttpResponse("OK")