From a08ba013a0d0d9302495b2ff1ec09c6750b8194d Mon Sep 17 00:00:00 2001 From: vrde Date: Tue, 6 Dec 2016 10:03:33 +0100 Subject: [PATCH] Remove dependency from bigchaindb.config --- bigchaindb/backend/rethinkdb/connection.py | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/bigchaindb/backend/rethinkdb/connection.py b/bigchaindb/backend/rethinkdb/connection.py index aa1bdbbe..4be9ca26 100644 --- a/bigchaindb/backend/rethinkdb/connection.py +++ b/bigchaindb/backend/rethinkdb/connection.py @@ -1,9 +1,11 @@ import time +import logging import rethinkdb as r -from bigchaindb.db import Connection -import bigchaindb +from bigchaindb.backend.connection import Connection + +logger = logging.getLogger(__name__) class RethinkDBConnection(Connection): @@ -14,19 +16,19 @@ class RethinkDBConnection(Connection): more times to run the query or open a connection. """ - def __init__(self, host=None, port=None, db=None, max_tries=3): + def __init__(self, host, port, dbname, max_tries=3): """Create a new Connection instance. Args: host (str, optional): the host to connect to. port (int, optional): the port to connect to. - db (str, optional): the database to use. + dbname (str, optional): the name of the database to use. max_tries (int, optional): how many tries before giving up. """ - self.host = host or bigchaindb.config['database']['host'] - self.port = port or bigchaindb.config['database']['port'] - self.db = db or bigchaindb.config['database']['name'] + self.host = host + self.port = port + self.dbname = dbname self.max_tries = max_tries self.conn = None @@ -38,7 +40,7 @@ class RethinkDBConnection(Connection): """ if self.conn is None: - self.connect() + self._connect() for i in range(self.max_tries): try: @@ -47,13 +49,12 @@ class RethinkDBConnection(Connection): if i + 1 == self.max_tries: raise else: - self.connect() + self._connect() - def connect(self): + def _connect(self): for i in range(self.max_tries): try: - self.conn = r.connect(host=self.host, port=self.port, - db=self.db) + self.conn = r.connect(host=self.host, port=self.port, db=self.dbname) except r.ReqlDriverError as exc: if i + 1 == self.max_tries: raise