Skip to content

Commit

Permalink
make client creation more similar to amostra, conftrak
Browse files Browse the repository at this point in the history
 * check client connection with server_info() call
 * catch known exceptions, throw new analysisstore exception
  • Loading branch information
JunAishima committed Mar 6, 2024
1 parent c6da609 commit 8a73811
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion analysisstore/server/astore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from pymongo import MongoClient, DESCENDING
import pymongo
import jsonschema
import json
import six
from .utils import AnalysisstoreException


class AStore:
Expand All @@ -16,7 +18,11 @@ def __init__(self, config, testing=False):
uri in string format, and database
"""
if not testing:
self.client = MongoClient(config["uri"])
try:
self.client = MongoClient(config["uri"])
self.client.server_info()
except (pymongo.errors.ConnectionFailure, pymongo.errors.ServerSelectionTimeoutError):
raise AnalysisstoreException("Unable to connect to MongoDB server...")
else:
import mongomock

Expand Down

0 comments on commit 8a73811

Please sign in to comment.