spam-filter/src/probes/probes.py
2020-10-08 16:08:59 +01:00

43 lines
1.4 KiB
Python

#!/usr/bin/env python
from flask import Flask
import requests, json
app = Flask(__name__)
@app.route('/health')
def health():
return json.dumps({'status': 'UP'}), 200, {'ContentType':'application/json'}
@app.route('/readiness')
def readiness():
result = requests.request("GET", 'http://0.0.0.0:9090/predict?tweet=Test%20Tweet%20for%20bitcoin%20predictions')
result = json.loads(result.text)
if result != "":
return json.dumps({
'status': 'UP',
'app': {
'name': 'CryptoSky spam filter',
'description': 'Projects spam filter service that classifies whether the tweet that is sent to it is spam or not',
'check_status': 'Success - Call to prediction endpoint',
'response': result
}
}), 200, {'ContentType': 'application/json'}
else:
return json.dumps({
'status': 'DOWN',
'app': {
'name': 'CryptoSky spam filter',
'description': 'Projects spam filter service that classifies whether the tweet that is sent to it is spam or not',
'check_status': 'Failure - Call to prediction endpoint',
'response': result
}
}), 503, {'ContentType': 'application/json'}
def runFlaskProbes():
app.run(port=9091, host="0.0.0.0")
if __name__ == '__main__':
runFlaskProbes()