introduce a timeout for MongoDB connection

This commit is contained in:
Davide Alberani 2018-11-02 16:08:51 +01:00
parent 2bd8ac96ee
commit d1e2fdbb31

14
ibt2.py
View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""I'll Be There, 2 (ibt2) - an oversimplified attendees registration system. """I'll Be There, 2 (ibt2) - an oversimplified attendees registration system.
Copyright 2016-2017 Davide Alberani <da@erlug.linux.it> Copyright 2016-2018 Davide Alberani <da@erlug.linux.it>
RaspiBO <info@raspibo.org> RaspiBO <info@raspibo.org>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
@ -18,6 +18,7 @@ limitations under the License.
import os import os
import re import re
import time
import logging import logging
import datetime import datetime
from operator import itemgetter from operator import itemgetter
@ -663,7 +664,16 @@ def run():
ssl_options = dict(certfile=options.ssl_cert, keyfile=options.ssl_key) ssl_options = dict(certfile=options.ssl_cert, keyfile=options.ssl_key)
# database backend connector # database backend connector
db_connector = monco.Monco(url=options.mongo_url, dbName=options.db_name) _count = 0
while True:
try:
db_connector = monco.Monco(url=options.mongo_url, dbName=options.db_name)
break
except Exception:
time.sleep(1)
_count += 1
if _count > 20:
raise
# global settings stored in the db # global settings stored in the db
global_settings = {} global_settings = {}