Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new 'ping' endpoint #112

Merged
merged 2 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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