fixed degraded state and log exceptions
This commit is contained in:
27
login.py
27
login.py
@@ -130,10 +130,15 @@ class NewsInformer(object):
|
|||||||
for attachment in newsdata['attachments']:
|
for attachment in newsdata['attachments']:
|
||||||
att_id = re.findall('Download/([0-9]+)?', attachment['url'])[0]
|
att_id = re.findall('Download/([0-9]+)?', attachment['url'])[0]
|
||||||
f = self.im.download(attachment['url'], directory='files')
|
f = self.im.download(attachment['url'], directory='files')
|
||||||
self.db_attachments.insert(
|
try:
|
||||||
{'id': att_id, 'filename':f}
|
if self.db_attachments.find_one(id=int(att_id)):
|
||||||
);
|
continue
|
||||||
self.db_news_attachments.insert({'att_id': att_id, 'news_id':newsdata['id']})
|
self.db_attachments.insert(
|
||||||
|
{'id': int(att_id), 'filename':f}
|
||||||
|
);
|
||||||
|
self.db_news_attachments.insert({'att_id': att_id, 'news_id':newsdata['id']})
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.exception('failed to store attachment')
|
||||||
self.db_news.insert(storenewsdata)
|
self.db_news.insert(storenewsdata)
|
||||||
if not self._notification_sent(news_item['id']):
|
if not self._notification_sent(news_item['id']):
|
||||||
self.logger.info('Notify %s about %s',
|
self.logger.info('Notify %s about %s',
|
||||||
@@ -524,15 +529,17 @@ def main():
|
|||||||
inforstr = 'Exception occured:\n{}:{}\n'.format(type(e).__name__, e)
|
inforstr = 'Exception occured:\n{}:{}\n'.format(type(e).__name__, e)
|
||||||
statusinfo['ok'] = False
|
statusinfo['ok'] = False
|
||||||
statusinfo['info'] = inforstr
|
statusinfo['info'] = inforstr
|
||||||
|
logger.exception("Something went wrong")
|
||||||
finally:
|
finally:
|
||||||
previous_status = db_api_status.find_one(username=user['username'])
|
previous_status = db_api_status.find_one(username=user['username'])
|
||||||
if previous_status is not None:
|
if previous_status is not None:
|
||||||
if previous_status['ok'] != statusinfo['ok']:
|
if previous_status['ok'] == True and statusinfo['ok'] == False:
|
||||||
if previous_status['degraded'] == True:
|
logger.error('Switching to degraded state %s', user['username'])
|
||||||
send_status_update(user['pushover'], statusinfo['info'])
|
statusinfo['degraded'] = True
|
||||||
else:
|
if previous_status['degraded'] == True and statusinfo['ok'] == False:
|
||||||
logger.error('Switching to degraded state %s', user['username'])
|
send_status_update(user['pushover'], statusinfo['info'])
|
||||||
statusinfo['degraded'] = True
|
if previous_status['degraded'] == True and statusinfo['ok'] == True:
|
||||||
|
send_status_update(user['pushover'], statusinfo['info'])
|
||||||
|
|
||||||
db_api_status.upsert(statusinfo, ['username'])
|
db_api_status.upsert(statusinfo, ['username'])
|
||||||
logger.info('ENDING--------------------- {}'.format(os.getpid()))
|
logger.info('ENDING--------------------- {}'.format(os.getpid()))
|
||||||
|
|||||||
Reference in New Issue
Block a user