diff --git a/configuration/kubernetes/deployment.yaml b/configuration/kubernetes/deployment.yaml index e6c6a12..0549190 100644 --- a/configuration/kubernetes/deployment.yaml +++ b/configuration/kubernetes/deployment.yaml @@ -6,7 +6,7 @@ metadata: name: RESOURCE_NAME namespace: production spec: - replicas: 1 + replicas: 0 selector: matchLabels: app: RESOURCE_NAME @@ -64,24 +64,24 @@ spec: ports: - containerPort: 9090 name: RESOURCE_NAME -# livenessProbe: -# httpGet: -# path: / -# port: 9090 -# initialDelaySeconds: 30 -# periodSeconds: 30 -# timeoutSeconds: 1 -# successThreshold: 1 -# failureThreshold: 3 -# readinessProbe: -# httpGet: -# port: 9090 -# path: / -# initialDelaySeconds: 30 -# periodSeconds: 5 -# timeoutSeconds: 1 -# successThreshold: 1 -# failureThreshold: 10 + livenessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 30 + periodSeconds: 30 + timeoutSeconds: 1 + successThreshold: 1 + failureThreshold: 3 + readinessProbe: + httpGet: + port: 5000 + path: /readiness + initialDelaySeconds: 30 + periodSeconds: 5 + timeoutSeconds: 1 + successThreshold: 1 + failureThreshold: 10 imagePullPolicy: Always resources: requests: diff --git a/src/main.py b/src/main.py index c9bf6bb..c76d1ff 100644 --- a/src/main.py +++ b/src/main.py @@ -6,12 +6,20 @@ sys.path.append('/home/price-collector/') from threading import Thread from pricing.collector import collector +from probes.probes import runFlaskProbes + def callCollector(args): collector(args) +def callProbes(): + runFlaskProbes() + if __name__=='__main__': + + Thread(target=callProbes).start() + # Dynamically create new child for each currency currencies = [ "btc_usd" ] - for i in range(len(currencies)): - Thread(target=callCollector, args=[currencies[i]]).start() \ No newline at end of file + # for i in range(len(currencies)): + # Thread(target=callCollector, args=[currencies[i]]).start() \ No newline at end of file diff --git a/src/pricing/collector.py b/src/pricing/collector.py index a55f5a9..d04f492 100644 --- a/src/pricing/collector.py +++ b/src/pricing/collector.py @@ -2,8 +2,6 @@ from datetime import datetime, timedelta -import sys - from time import sleep from pricing.bitfinex import bitfinexPublicTicker, bitfinexHighLowVol 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..4bfc6b3 --- /dev/null +++ b/src/probes/probes.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +from flask import Flask + +import json + +from pricing.coinbase import coinbasePublicTicker + +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 = coinbasePublicTicker('btc_usd', logger) + + 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() + +if __name__ == '__main__': + runFlaskProbes() \ No newline at end of file