diff options
author | Paweł Dybiec <pawel.to.malpa@gmail.com> | 2019-04-17 17:48:49 +0200 |
---|---|---|
committer | Paweł Dybiec <pawel.to.malpa@gmail.com> | 2019-04-17 17:48:49 +0200 |
commit | 76173530dcacc33725590a7c6d8862fac5466dc3 (patch) | |
tree | 8d87481f094ff0f5c189be7ab95c32e9eb6e8e65 /compose/app/app.py | |
parent | Added vault.password to gitignore (diff) |
Change docker compose dir
Diffstat (limited to 'compose/app/app.py')
-rw-r--r-- | compose/app/app.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/compose/app/app.py b/compose/app/app.py new file mode 100644 index 0000000..9bf5d90 --- /dev/null +++ b/compose/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) |