spam-filter/src/probes/probes.py
2020-10-14 15:42:11 +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://localhost:9090/predictProbeTest')
# 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': 'spam', 'tweet': 'Fake Test Tweet'}"
}
}), 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': 'spam', 'tweet': 'Fake Test Tweet'}"
}
}), 503, {'ContentType': 'application/json'}
def runFlaskProbes():
app.run(port=9091, host="0.0.0.0")
if __name__ == '__main__':
runFlaskProbes()