Check if cache is broken
This commit is contained in:
parent
8799b10525
commit
dbdcfaa921
|
@ -5,6 +5,7 @@ logging.basicConfig(
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import threading
|
import threading
|
||||||
|
import traceback
|
||||||
import time
|
import time
|
||||||
import shelve
|
import shelve
|
||||||
from urllib.parse import urlparse, parse_qs
|
from urllib.parse import urlparse, parse_qs
|
||||||
|
@ -42,8 +43,14 @@ with shelve.open(DATA_FILE) as db:
|
||||||
nid = news_ref_to_id[ref]
|
nid = news_ref_to_id[ref]
|
||||||
_ = news_cache[nid]
|
_ = news_cache[nid]
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
logging.error('Unable to find key {}. Trying to remove...'.format(str(e)))
|
ekey = str(e)
|
||||||
news_list.remove(str(e))
|
logging.error('Unable to find key {}. Trying to remove...'.format(ekey))
|
||||||
|
if ekey in news_cache:
|
||||||
|
news_cache.remove(ekey)
|
||||||
|
if ekey in news_list:
|
||||||
|
news_list.remove(ekey)
|
||||||
|
if ekey in news_ref_to_id:
|
||||||
|
news_ref_to_id.remove(ekey)
|
||||||
|
|
||||||
def get_story(sid):
|
def get_story(sid):
|
||||||
if sid in news_cache:
|
if sid in news_cache:
|
||||||
|
@ -73,8 +80,12 @@ def api():
|
||||||
try:
|
try:
|
||||||
front_page = [news_cache[news_ref_to_id[ref]] for ref in news_list]
|
front_page = [news_cache[news_ref_to_id[ref]] for ref in news_list]
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
logging.error('Unable to find key {}. Trying to remove...'.format(str(e)))
|
ekey = str(e)
|
||||||
news_list.remove(str(e))
|
logging.error('Unable to find key {}. Trying to remove...'.format(ekey))
|
||||||
|
if ekey in news_cache:
|
||||||
|
news_cache.remove(ekey)
|
||||||
|
if ekey in news_list:
|
||||||
|
news_list.remove(ekey)
|
||||||
|
|
||||||
front_page = [copy.copy(x) for x in front_page if 'title' in x and x['title']]
|
front_page = [copy.copy(x) for x in front_page if 'title' in x and x['title']]
|
||||||
front_page = front_page[:60]
|
front_page = front_page[:60]
|
||||||
|
@ -125,6 +136,7 @@ def submit():
|
||||||
|
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
logging.error('Problem with article submission: {} - {}'.format(e.__class__.__name__, str(e)))
|
logging.error('Problem with article submission: {} - {}'.format(e.__class__.__name__, str(e)))
|
||||||
|
print(traceback.format_exc())
|
||||||
abort(400)
|
abort(400)
|
||||||
|
|
||||||
|
|
||||||
|
@ -194,9 +206,19 @@ def feed_thread():
|
||||||
|
|
||||||
# update current stories
|
# update current stories
|
||||||
if news_index < len(news_list):
|
if news_index < len(news_list):
|
||||||
update_ref = news_list[news_index]
|
try:
|
||||||
update_id = news_ref_to_id[update_ref]
|
update_ref = news_list[news_index]
|
||||||
news_story = news_cache[update_id]
|
update_id = news_ref_to_id[update_ref]
|
||||||
|
news_story = news_cache[update_id]
|
||||||
|
except KeyError as e:
|
||||||
|
ekey = str(e)
|
||||||
|
logging.error('Unable to find key {}. Trying to remove...'.format(ekey))
|
||||||
|
if ekey in news_cache:
|
||||||
|
news_cache.remove(ekey)
|
||||||
|
if ekey in news_list:
|
||||||
|
news_list.remove(ekey)
|
||||||
|
if ekey in news_ref_to_id:
|
||||||
|
news_ref_to_id.remove(ekey)
|
||||||
valid = feed.update_story(news_story)
|
valid = feed.update_story(news_story)
|
||||||
if valid:
|
if valid:
|
||||||
archive.update(news_story)
|
archive.update(news_story)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user