diff --git a/Dockerfile b/Dockerfile index c606907..76b9b2a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,4 +7,5 @@ RUN apt update -y && \ COPY . /home/spam-filter/. RUN python3 /home/spam-filter/configuration/scripts/nltk_package_downloads.py EXPOSE 9090 +EXPOSE 9091 CMD ["python", "/home/spam-filter/src/main.py"] \ No newline at end of file diff --git a/configuration/kubernetes/service.yaml b/configuration/kubernetes/service.yaml index c0a5e76..c3ed717 100644 --- a/configuration/kubernetes/service.yaml +++ b/configuration/kubernetes/service.yaml @@ -12,5 +12,8 @@ spec: - port: 9090 protocol: HTTP targetPort: 9090 + - port: 9091 + protocol: HTTP + targetPort: 9091 sessionAffinity: None type: ClusterIP \ No newline at end of file diff --git a/src/main.py b/src/main.py index b75962b..3031542 100644 --- a/src/main.py +++ b/src/main.py @@ -10,6 +10,8 @@ from tweets.tweetFilter import tweetFilter from flask import Flask, request +from probes.probes import runFlaskProbes + app = Flask(__name__) filter = tweetFilter() @@ -24,14 +26,19 @@ def tweetPredict(): def callTweetFilter(): filter.tweetFilterTrain() - app.run(port=9090) + app.run(port=9090, host="0.0.0.0") # def callNewsFilter(): # newsFilter() +def callProbes(): + runFlaskProbes() + if __name__ == '__main__': print("Console: ", "==== Spam Filter - Tweets & News ====") sys.stdout.flush() + Thread(target=callProbes).start() + Thread(target=callTweetFilter).start() # Thread(target=callNewsFilter).start() \ No newline at end of file diff --git a/src/probes/__init__.py b/src/probes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/probes/probes.py b/src/probes/probes.py new file mode 100644 index 0000000..8e9fb8a --- /dev/null +++ b/src/probes/probes.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +from flask import Flask + +import json + +import logging as logger +logger.basicConfig( + level=logger.INFO, + format="%(asctime)s: %(levelname)s -- %(message)s", + datefmt='%Y-%m-%d %H:%M:%S' +) + +app = Flask(__name__) + +@app.route('/health') +def health(): + return json.dumps({'status': 'UP'}), 200, {'ContentType':'application/json'} + +@app.route('/readiness') +def readiness(): + # Can it make a call to an exchange? + price = 23 + + if price != 0 : + return json.dumps({ + 'status': 'UP', + 'app': { + 'name': 'CryptoSky Price Collector', + 'description': 'Projects Price Collector service that collects the: High, Low, Open, Close prices, Volume and calculates average price for the hour.', + 'check_status': 'Success - Call to coinbase exchange', + 'price': price + } + }), 200, {'ContentType': 'application/json'} + else: + return json.dumps({ + 'status': 'DOWN', + 'app': { + 'name': 'CryptoSky Price Collector', + 'description': 'Projects Price Collector service that collects the: High, Low, Open, Close prices, Volume and calculates average price for the hour.', + 'check_status': 'Failed - Call to coinbase exchange', + 'price': price + } + }), 503, {'ContentType': 'application/json'} + +def runFlaskProbes(): + app.run(port=9091, host="0.0.0.0") + +if __name__ == '__main__': + runFlaskProbes() \ No newline at end of file diff --git a/src/tweets/tweetFilter.py b/src/tweets/tweetFilter.py index a13c101..c23630d 100644 --- a/src/tweets/tweetFilter.py +++ b/src/tweets/tweetFilter.py @@ -244,7 +244,7 @@ class tweetFilter(object): pass def tweetFilterTrain(self): - self.Filter = multinomialNaiveBayes("/home/spam-filter/src/resources/tweet_spam_ham.csv") + self.Filter = multinomialNaiveBayes("src/resources/tweet_spam_ham.csv") self.Filter.trainFilter()