mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Remove dependency from bigchaindb.config
This commit is contained in:
parent
87c7228bc4
commit
a08ba013a0
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user