Browse Source

Lightweight 'server status' API endpoint, to be used by external load balancers

pull/114/merge v1.0
Pēteris Caune 8 years ago
parent
commit
c073cb0b3a
2 changed files with 10 additions and 0 deletions
  1. +1
    -0
      hc/api/urls.py
  2. +9
    -0
      hc/api/views.py

+ 1
- 0
hc/api/urls.py View File

@ -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),
]

+ 9
- 0
hc/api/views.py View File

@ -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")

Loading…
Cancel
Save