Skip to content

Commit

Permalink
fix: fix mongoDB healthcheck
Browse files Browse the repository at this point in the history
catch ServerSelectionTimeoutError errors
  • Loading branch information
raphael0202 committed Dec 2, 2022
1 parent f30e055 commit 1a6607d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions robotoff/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from influxdb_client import InfluxDBClient
from playhouse.postgres_ext import PostgresqlExtDatabase
from pymongo import MongoClient
from pymongo.errors import ServerSelectionTimeoutError

from robotoff import settings
from robotoff.utils import get_logger
Expand All @@ -14,9 +15,12 @@

def test_connect_mongodb():
logger.debug("health: testing mongodb connection to %s", settings.MONGO_URI)
client = MongoClient(settings.MONGO_URI)
client.server_info()
return True, "MongoDB db connection success !"
client = MongoClient(settings.MONGO_URI, serverSelectionTimeoutMS=5_000)
try:
client.server_info()
except ServerSelectionTimeoutError:
return False, "MongoDB DB connection failed!"
return True, "MongoDB DB connection succeeded!"


def test_connect_postgres():
Expand Down

0 comments on commit 1a6607d

Please sign in to comment.