Commit 671ef31a authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added existing mongo connection checks to mongo init.

parent ba2d9ba9
Pipeline #65587 failed with stages
in 16 minutes and 7 seconds
......@@ -20,9 +20,10 @@ from nomad import infrastructure, datamodel, utils
from .admin import admin'''Add, import, export users.''')
def users():
@users.command(help='Import users to keycloak from a JSON file.', name='import')
......@@ -43,4 +44,3 @@ def import_command(path_to_users_file):
print('Imported %s' %
except Exception as e:
logger.error('could not import user', exc_info=e)
......@@ -23,7 +23,8 @@ import os.path
import shutil
from elasticsearch.exceptions import RequestError
from elasticsearch_dsl import connections
from mongoengine import connect
from mongoengine import connect, disconnect
from mongoengine.connection import MongoEngineConnectionError
import smtplib
from email.mime.text import MIMEText
from keycloak import KeycloakOpenID, KeycloakAdmin
......@@ -75,7 +76,15 @@ def setup_logging():
def setup_mongo():
""" Creates connection to mongodb. """
global mongo_client
mongo_client = connect(db=config.mongo.db_name,, port=config.mongo.port)
if mongo_client is not None:
return mongo_client
mongo_client = connect(db=config.mongo.db_name,, port=config.mongo.port)
except MongoEngineConnectionError:
mongo_client = connect(db=config.mongo.db_name,, port=config.mongo.port)'setup mongo connection')
return mongo_client
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment