From 03bbfaa93e0b565b4db5c4ef7b685ecf3b245287 Mon Sep 17 00:00:00 2001 From: Paweł Dybiec Date: Sun, 2 Dec 2018 01:21:20 +0100 Subject: Sample services --- composer/app/app.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 composer/app/app.py (limited to 'composer/app/app.py') diff --git a/composer/app/app.py b/composer/app/app.py new file mode 100644 index 0000000..9bf5d90 --- /dev/null +++ b/composer/app/app.py @@ -0,0 +1,29 @@ +import time + +import redis +from flask import Flask + + +app = Flask(__name__) +cache = redis.Redis(host='redis', port=6379) + + +def get_hit_count(): + retries = 5 + while True: + try: + return cache.incr('hits') + except redis.exceptions.ConnectionError as exc: + if retries == 0: + raise exc + retries -= 1 + time.sleep(0.5) + + +@app.route('/') +def hello(): + count = get_hit_count() + return 'Hello from this site! I have been seen {} times.\n'.format(count) + +if __name__ == "__main__": + app.run(host="0.0.0.0", debug=True) -- cgit 1.4.1