Handle case when tracker is down and flask lacks cache.
parent
4dad65bd90
commit
5eefb6fa67
|
@ -9,9 +9,12 @@ import logging
|
||||||
|
|
||||||
CACHE_AGE_MAX = 600
|
CACHE_AGE_MAX = 600
|
||||||
CACHE_LOCATION='/tmp/runs.json'
|
CACHE_LOCATION='/tmp/runs.json'
|
||||||
|
TRACKER_URL='https://gamesdonequick.com/tracker/search/?type=run&event=20'
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class KappaException(Exception):
|
||||||
|
pass
|
||||||
class GDQException(Exception):
|
class GDQException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -38,15 +41,18 @@ def fetch_or_cache_runs():
|
||||||
|
|
||||||
|
|
||||||
def load_run_cache():
|
def load_run_cache():
|
||||||
with open(CACHE_LOCATION, 'r') as f:
|
if os.path.isfile(CACHE_LOCATION):
|
||||||
string = f.read()
|
with open(CACHE_LOCATION, 'r') as f:
|
||||||
return json.loads(string)
|
string = f.read()
|
||||||
|
return json.loads(string)
|
||||||
|
else:
|
||||||
|
raise KappaException("GDQ Tracker Appears to be down, and I don't have a saved copy. Try again later.")
|
||||||
|
|
||||||
|
|
||||||
def fetch_runs():
|
def fetch_runs():
|
||||||
try:
|
try:
|
||||||
logger.warn("Re-fetching cache")
|
logger.warn("Re-fetching cache")
|
||||||
r = requests.get('https://gamesdonequick.com/tracker/search/?type=run&event=20', timeout=3)
|
r = requests.get(TRACKER_URL, timeout=3)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise GDQException("GDQ not returning 200")
|
raise GDQException("GDQ not returning 200")
|
||||||
output = r.json()
|
output = r.json()
|
||||||
|
|
Loading…
Reference in New Issue