Skip to content

Commit

Permalink
Merge pull request #30 from JunAishima/harmonize-kwargs-client-check
Browse files Browse the repository at this point in the history
Harmonize kwargs, client check
  • Loading branch information
gwbischof authored Mar 7, 2024
2 parents f1661e2 + 8082af4 commit 271ee0d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions analysisstore/ignition.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def start_server(config=None):
parser = argparse.ArgumentParser()
parser.add_argument('--database', dest='database', type=str,
help='name of database to use')
parser.add_argument('--mongo-uri',
parser.add_argument('--mongo_uri',
dest='mongo_uri', type=str,
help='uri of Mongo DB')
parser.add_argument('--timezone', dest='timezone', type=str,
help='Local timezone')
parser.add_argument('--service-port', dest='service_port', type=int,
parser.add_argument('--service_port', dest='service_port', type=int,
help='port listen to for clients')
parser.add_argument('--log-file_prefix', dest='log_file_prefix', type=str,
help='Log file name that tornado logs are dumped')
Expand Down
9 changes: 8 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,12 @@ 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"])
# Proactively check that connection to server is working.
self.client.server_info()
except (pymongo.errors.ConnectionFailure, pymongo.errors.ServerSelectionTimeoutError):
raise AnalysisstoreException("Unable to connect to MongoDB server...")
else:
import mongomock

Expand Down
5 changes: 4 additions & 1 deletion analysisstore/server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import ujson
import pymongo.cursor

class AnalysisstoreException(Exception):
pass


SCHEMA_PATH = 'schemas'
SCHEMA_NAMES = {'analysis_header': 'analysis_header.json',
Expand Down Expand Up @@ -73,4 +76,4 @@ def return2client(handler, payload):
except StopIteration:
break
handler.write(']')
handler.finish()
handler.finish()
4 changes: 2 additions & 2 deletions analysisstore/test/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
def astore_setup():
f = os.path.dirname(os.path.realpath(__file__))
proc = Popen(["python", "../startup.py",
"--mongo-uri",
"--mongo_uri",
str(TESTING_CONFIG['mongouri']),
"--database", TESTING_CONFIG['database'],
"--timezone", TESTING_CONFIG['timezone'],
"--service-port",
"--service_port",
str(TESTING_CONFIG['serviceport'])], cwd=f)
ttime.sleep(1.3) # make sure the process is started
return proc
Expand Down

0 comments on commit 271ee0d

Please sign in to comment.