forked from tanner/qotnews
feed thread loop.
This commit is contained in:
parent
c1b7877f4b
commit
4ec50e20cb
|
@ -28,9 +28,6 @@ from flask_cors import CORS
|
|||
database.init()
|
||||
search.init()
|
||||
|
||||
news_length = 0
|
||||
news_index = 0
|
||||
|
||||
def new_id():
|
||||
nid = gen_rand_id()
|
||||
while database.get_story(nid):
|
||||
|
@ -145,13 +142,7 @@ def static_story(sid):
|
|||
|
||||
http_server = WSGIServer(('', 33842), flask_app)
|
||||
|
||||
def feed_thread():
|
||||
global news_index, news_length
|
||||
|
||||
try:
|
||||
while True:
|
||||
# onboard new stories
|
||||
if news_index == 0:
|
||||
def _add_new_refs():
|
||||
for ref, source in feed.get_list():
|
||||
if database.get_story_by_ref(ref):
|
||||
continue
|
||||
|
@ -162,19 +153,13 @@ def feed_thread():
|
|||
except database.IntegrityError:
|
||||
continue
|
||||
|
||||
ref_list = database.get_reflist()
|
||||
news_length = len(ref_list)
|
||||
|
||||
# update current stories
|
||||
if news_index < len(ref_list):
|
||||
item = ref_list[news_index]
|
||||
|
||||
def _update_current_story(item):
|
||||
try:
|
||||
story = database.get_story(item['sid']).data
|
||||
except AttributeError:
|
||||
story = dict(id=item['sid'], ref=item['ref'], source=item['source'])
|
||||
|
||||
logging.info('Updating story: ' + str(story['ref']) + ', index: ' + str(news_index))
|
||||
logging.info('Updating story: {}'.format(str(story['ref'])))
|
||||
|
||||
valid = feed.update_story(story)
|
||||
if valid:
|
||||
|
@ -183,14 +168,23 @@ def feed_thread():
|
|||
else:
|
||||
database.del_ref(item['ref'])
|
||||
logging.info('Removed ref {}'.format(item['ref']))
|
||||
else:
|
||||
logging.info('Skipping index: ' + str(news_index))
|
||||
|
||||
def feed_thread():
|
||||
ref_list = []
|
||||
try:
|
||||
while True:
|
||||
# onboard new stories
|
||||
if not len(ref_list):
|
||||
_add_new_refs()
|
||||
ref_list = database.get_reflist()
|
||||
|
||||
# update current stories
|
||||
if len(ref_list):
|
||||
item = ref_list.pop(0)
|
||||
_update_current_story(item)
|
||||
|
||||
gevent.sleep(6)
|
||||
|
||||
news_index += 1
|
||||
if news_index >= news_length: news_index = 0
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logging.info('Ending feed thread...')
|
||||
except ValueError as e:
|
||||
|
|
Loading…
Reference in New Issue
Block a user