summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <yuval@y3xz.com>2015-11-07 01:40:19 +0200
committerYuval Adam <yuval@y3xz.com>2015-11-07 01:40:19 +0200
commit6c779d2f72d03cc2a318f1d09781586fdca996d2 (patch)
tree0a6a0d760e9a4724dd4c8dfd4db2912768d87d8f
parentda35e45efb7eca18ead4e266e22bc33d4035efcd (diff)
Handle local dev redis behavior gracefully
-rw-r--r--README.md6
-rw-r--r--geshem.py11
2 files changed, 12 insertions, 5 deletions
diff --git a/README.md b/README.md
index 38994e7..99f7940 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ A rain radar clone for Mapbox GL, see it live at: [http://geshem.space](http://g
## Dev
- Python 3.5
- - Redis
+ - Redis (optional, recommended)
Setup a virtualenv:
@@ -14,8 +14,10 @@ $ mkvirtualenv -p `which python3` geshem
$ pip install -r requirements.txt
```
-Make sure you have a stupid `redis-server` running on localhost, then just run:
+Then just run:
```bash
$ python geshem.py
```
+
+Make sure you have a stupid `redis-server` running on localhost to enjoy some sane caching.
diff --git a/geshem.py b/geshem.py
index 361aaf8..209eb5e 100644
--- a/geshem.py
+++ b/geshem.py
@@ -4,6 +4,7 @@ import requests
from flask import Flask, render_template
from os import environ
from pathlib import Path
+from redis.exceptions import ConnectionError
MAPS_JSON = 'http://map.govmap.gov.il/rainradar/radar.json'
STATIC_DIR = Path(__file__).resolve().parents[0] / 'static'
@@ -28,9 +29,13 @@ def home():
@app.after_request
def update_images(response):
# poor man's background task
- if not redis.get('fresh'):
- redis.setex('fresh', 'yes', 60)
- fetch_latest_images()
+ try:
+ if not redis.get('fresh'):
+ redis.setex('fresh', 'yes', 60)
+ fetch_latest_images()
+ except ConnectionError as e:
+ if app.debug:
+ fetch_latest_images()
return response
if __name__ == '__main__':