From 6c779d2f72d03cc2a318f1d09781586fdca996d2 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Sat, 7 Nov 2015 01:40:19 +0200 Subject: Handle local dev redis behavior gracefully --- README.md | 6 ++++-- geshem.py | 11 ++++++++--- 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__': -- cgit v1.3.1