def mongo_connect(*args, **kwargs):
"""Connect mongoengine to mongo db. This connection is reused everywhere"""
for _ in xrange(30):
try:
log.info("Attempting to connect to %s at %s...", config.MONGO_DB,
config.MONGO_URI)
me.connect(db=config.MONGO_DB, host=config.MONGO_URI)
except Exception as exc:
log.warning("Error connecting to mongo, will retry in 1 sec: %r",
exc)
time.sleep(1)
else:
log.info("Connected...")
break
else:
log.critical("Unable to connect to %s at %s: %r", config.MONGO_DB,
config.MONGO_URI, exc)
raise exc
评论列表
文章目录