Created
April 12, 2016 11:41
-
-
Save zoidyzoidzoid/1163252eae4386c25f9a9f427bcd0b5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
DJANGO | |
""" | |
from django.http import JsonResponse | |
def simple(request): | |
return JsonResponse({'health': 'OK'}) | |
""" | |
FLASK | |
""" | |
from flask import Blueprint, current_app, jsonify | |
from pykafka import KafkaClient | |
from pykafka.exceptions import NoBrokersAvailableError | |
healthchecks = Blueprint('healthchecks', __name__) | |
@healthchecks.route('/memcached') | |
def memcached_healthcheck(): | |
current_app.cache.set('test_key', 'test_value', timeout=20) | |
if current_app.cache.get('test_key') == 'test_value': | |
return jsonify(health='OK', cache='OK') | |
else: | |
return jsonify(health='OK', cache='Error'), 400 | |
@healthchecks.route('/simple') | |
def simple_healthcheck(): | |
return jsonify(health='OK') | |
@healthchecks.route('/kafka') | |
def kafka_healthcheck(): | |
try: | |
KafkaClient(NEW_KAFKA_NETLOC, socket_timeout_ms=500) | |
except NoBrokersAvailableError: | |
return jsonify(health='OK', kafka='Error'), 400 | |
return jsonify(health='OK', kafka='OK') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment