Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #218 from glogiotatidis/watchman
Browse files Browse the repository at this point in the history
Watchman
  • Loading branch information
glogiotatidis authored Apr 2, 2018
2 parents 70ea7a8 + 98f7642 commit 40c0d8a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
8 changes: 1 addition & 7 deletions careers/base/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
from django.core.urlresolvers import reverse

from careers.base.tests import TestCase
from careers.careers.tests import PositionFactory


class HealthzViewTests(TestCase):
def test_ok(self):
PositionFactory.create()
response = self.client.get(reverse('healthz'))
response = self.client.get(reverse('watchman.ping'))
self.assertEqual(response.status_code, 200)

def test_fail(self):
with self.assertRaises(AssertionError):
self.client.get(reverse('healthz'))
8 changes: 0 additions & 8 deletions careers/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@

from raven.contrib.django.models import client

from careers.careers.models import Position


def robots(request):
action = 'Allow' if settings.ENGAGE_ROBOTS else 'Disallow'
return HttpResponse('User-agent: *\n{}: /'.format(action), content_type='text/plain')


def healthz(request):
"""For use with Healthchecks."""
assert Position.objects.exists(), "No positions exist"
return HttpResponse('OK')


@csrf_exempt
@require_POST
def csp_violation_capture(request):
Expand Down
9 changes: 9 additions & 0 deletions careers/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'django_jinja',
'django_extensions',
'raven.contrib.django.raven_compat',
'watchman',

# Django apps
'django.contrib.staticfiles',
Expand Down Expand Up @@ -208,8 +209,16 @@
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_REDIRECT_EXEMPT = [
r'^healthz/$',
r'^readiness/$',
]

# watchman
WATCHMAN_DISABLE_APM = True
WATCHMAN_CHECKS = (
'watchman.checks.caches',
'watchman.checks.databases',
)

CACHES = {
'default': config('CACHE_URL', default='locmem://', cast=django_cache_url.parse),
}
Expand Down
5 changes: 4 additions & 1 deletion careers/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.conf.urls import include, url
from django.views.static import serve as servestatic

from watchman import views as watchman_views

from base import views

urlpatterns = [
Expand All @@ -16,7 +18,8 @@
url(r'^robots\.txt$', views.robots, name='robots'),

# healthz
url(r'^healthz/$', views.healthz, name='healthz'),
url(r'^healthz/$', watchman_views.ping, name='watchman.ping'),
url(r'^readiness/$', watchman_views.status, name='watchman.status'),

# Generate a robots.txt
url(r'^csp-violation-capture$', views.csp_violation_capture,
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,9 @@ django-allow-cidr==0.3.0 \
netaddr==0.7.19 \
--hash=sha256:56b3558bd71f3f6999e4c52e349f38660e54a7a8a9943335f73dfc96883e08ca \
--hash=sha256:38aeec7cdd035081d3a4c306394b19d677623bf76fa0913f6695127c7753aefd
django-watchman==0.14.0 \
--hash=sha256:0e953c27b8f4c07dcb96712ea4a304de085cf44e7829a33c6e12477cd60b8673 \
--hash=sha256:d2094f09d1bdaa0f24e710da69d77433bd9011c18f74024acb332a2fcfcafe68
django-jsonview==1.1.0 \
--hash=sha256:b78cc4e3d75e119966d1ad2ae832c38f94ede967e847abee48df51059ddda040 \
--hash=sha256:9907d4958097db243419063477fa504ff63c7483687f852175452a1ff0d5582a

0 comments on commit 40c0d8a

Please sign in to comment.