Skip to content

Commit

Permalink
Adds a new 'ping' endpoint
Browse files Browse the repository at this point in the history
The endpoint simply returns the text 'pong' without running all of the checks.
  • Loading branch information
dhoffman34 committed Jan 5, 2018
1 parent cc3c180 commit 3847a89
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ watchman may open too many connections as it checks each database or cache.
You can set the ``WATCHMAN_DATABASES`` or ``WATCHMAN_CACHES`` settings in order
to override the default set of databases and caches to be monitored.

Ping
****

If you want to simply check that your application is running and able to handle
requests, you can call ping:

GET http://127.0.0.1:8000/watchman/ping/

It will return the text ``pong`` with a 200 status code. Calling this doesn't
run any of the checks.

Django management command
*************************

Expand Down
13 changes: 13 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,19 @@ def test_response_version_header(self):
self.assertTrue(response.has_header('X-Watchman-Version'))


class TestPing(unittest.TestCase):
def setUp(self):
# Ensure that every test executes with separate settings
reload_settings()

def test_returns_pong(self):
request = RequestFactory().get('/')
response = views.ping(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content.decode(), 'pong')
self.assertEqual(response['Content-Type'], 'text/plain')


class TestEmailCheck(DjangoTestCase):
def setUp(self):
# Ensure that every test executes with separate settings
Expand Down
1 change: 1 addition & 0 deletions watchman/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
urlpatterns = [
url(r'^$', views.status, name="status"),
url(r'^dashboard/$', views.dashboard, name="dashboard"),
url(r'^ping/$', views.ping, name="ping"),
]
8 changes: 7 additions & 1 deletion watchman/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import warnings

from django.db.transaction import non_atomic_requests
from django.http import Http404
from django.http import Http404, HttpResponse
from django.shortcuts import render
from django.utils.translation import ugettext as _
from jsonview.decorators import json_view
Expand Down Expand Up @@ -69,6 +69,12 @@ def status(request):
return response, http_code, {WATCHMAN_VERSION_HEADER: __version__}


def ping(request):
_deprecation_warnings()

return HttpResponse('pong', content_type='text/plain')


@auth
@non_atomic_requests
def dashboard(request):
Expand Down

0 comments on commit 3847a89

Please sign in to comment.