From 8a73811d1ebec10a8bb666bc86f95a68f509261b Mon Sep 17 00:00:00 2001 From: Jun Aishima Date: Wed, 6 Mar 2024 18:02:49 -0500 Subject: [PATCH] make client creation more similar to amostra, conftrak * check client connection with server_info() call * catch known exceptions, throw new analysisstore exception --- analysisstore/server/astore.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/analysisstore/server/astore.py b/analysisstore/server/astore.py index 81c964f..ea984e0 100644 --- a/analysisstore/server/astore.py +++ b/analysisstore/server/astore.py @@ -1,7 +1,9 @@ from pymongo import MongoClient, DESCENDING +import pymongo import jsonschema import json import six +from .utils import AnalysisstoreException class AStore: @@ -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