mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 10:30:03 -03:30
more robust check added to mongo db connection
Calling mongoengine (or pymongo) connect() after already calling connect() resulting in getting the first connection (connection pooling). This is bad if we are relying on connect() to determine if mongo is up. Added executing a ping/pong command after the connect() command to ensure mongo is still/really up.
This commit is contained in:
parent
58be1b1f51
commit
78ac2ccb55
@ -4,6 +4,7 @@
|
||||
from django.conf import settings
|
||||
from mongoengine import connect
|
||||
from mongoengine.connection import ConnectionError
|
||||
from pymongo.errors import AutoReconnect
|
||||
|
||||
def test_mongo_connection():
|
||||
# Connect to Mongo
|
||||
@ -14,13 +15,14 @@ def test_mongo_connection():
|
||||
raise ConnectionError
|
||||
|
||||
# Attempt to connect to the MongoDB database.
|
||||
connect(settings.MONGO_DB,
|
||||
host=settings.MONGO_HOST,
|
||||
port=int(settings.MONGO_PORT),
|
||||
username=settings.MONGO_USERNAME,
|
||||
password=settings.MONGO_PASSWORD,
|
||||
tz_aware=settings.USE_TZ)
|
||||
db = connect(settings.MONGO_DB,
|
||||
host=settings.MONGO_HOST,
|
||||
port=int(settings.MONGO_PORT),
|
||||
username=settings.MONGO_USERNAME,
|
||||
password=settings.MONGO_PASSWORD,
|
||||
tz_aware=settings.USE_TZ)
|
||||
db[settings.MONGO_DB].command('ping')
|
||||
return True
|
||||
except ConnectionError:
|
||||
except ConnectionError, AutoReconnect:
|
||||
return False
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user