Skip to content

Commit

Permalink
feat(bookkeeping): fixing pep8 issues & simpler checking of env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
deepankarm authored and JoanFM committed Sep 17, 2020
1 parent b288366 commit d25afa3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion extra-requirements.txt
Expand Up @@ -59,4 +59,4 @@ pytest-cov: test
pytest-repeat: test
flaky: test
mock: test
pymongo[srv]: hub
pymongo[srv]: hub, devel
11 changes: 5 additions & 6 deletions jina/docker/checker.py
Expand Up @@ -81,9 +81,8 @@ def is_error_message(s):

def db_env_variables_set():
""" Checks if any of the db env variables are not set """
none_exists = None in [
os.environ.get('db_username', None), os.environ.get('db_password', None),
os.environ.get('db_hostname', None), os.environ.get('db_name', None),
os.environ.get('db_collection', None)
]
return not none_exists
keys = ['JINA_DB_HOSTNAME', 'JINA_DB_USERNAME', 'JINA_DB_PASSWORD', 'JINA_DB_NAME', 'JINA_DB_COLLECTION']
for k in keys:
if k not in os.environ:
return False
return True
6 changes: 3 additions & 3 deletions jina/docker/database.py
Expand Up @@ -5,7 +5,7 @@
from ..logging import get_logger


class MongoDBHandler():
class MongoDBHandler:
"""
Mongodb Handler to connect to the database & insert documents in the collection
"""
Expand All @@ -29,9 +29,9 @@ def connect(self):
self.client.admin.command('ismaster')
self.logger.info('Successfully connected to the database')
except pymongo.errors.ConnectionFailure:
raise MongoDBException("Database server is not available")
raise MongoDBException('Database server is not available')
except pymongo.errors.ConfigurationError:
raise MongoDBException("Credentials passed are not correct!")
raise MongoDBException('Credentials passed are not correct!')
except pymongo.errors.PyMongoError as exp:
raise MongoDBException(exp)
return self
Expand Down
10 changes: 5 additions & 5 deletions jina/docker/hubio.py
Expand Up @@ -313,11 +313,11 @@ def _write_summary_to_db(self, summary):
return

build_summary = handle_dot_in_keys(document=summary)
with MongoDBHandler(hostname=os.environ['db_hostname'],
username=os.environ['db_username'],
password=os.environ['db_password'],
database_name=os.environ['db_name'],
collection_name=os.environ['db_collection']) as db:
with MongoDBHandler(hostname=os.environ['JINA_DB_HOSTNAME'],
username=os.environ['JINA_DB_USERNAME'],
password=os.environ['JINA_DB_PASSWORD'],
database_name=os.environ['JINA_DB_NAME'],
collection_name=os.environ['JINA_DB_COLLECTION']) as db:
inserted_id = db.insert(document=build_summary)
self.logger.debug(f'Inserted the build + push summary in db with id {inserted_id}')

Expand Down

0 comments on commit d25afa3

Please sign in to comment.