Unverified Commit 104987a2 authored by Jin Hyuk Chang's avatar Jin Hyuk Chang Committed by GitHub

Setting idle connection timeout in neo4j_extractor (#85)

parent fd8c24d6
...@@ -2,7 +2,7 @@ import importlib ...@@ -2,7 +2,7 @@ import importlib
import logging import logging
from typing import Any, Iterator, Union # noqa: F401 from typing import Any, Iterator, Union # noqa: F401
from pyhocon import ConfigTree # noqa: F401 from pyhocon import ConfigTree, ConfigFactory # noqa: F401
from neo4j.v1 import GraphDatabase from neo4j.v1 import GraphDatabase
from databuilder.extractor.base_extractor import Extractor from databuilder.extractor.base_extractor import Extractor
...@@ -19,6 +19,9 @@ class Neo4jExtractor(Extractor): ...@@ -19,6 +19,9 @@ class Neo4jExtractor(Extractor):
MODEL_CLASS_CONFIG_KEY = 'model_class' MODEL_CLASS_CONFIG_KEY = 'model_class'
NEO4J_AUTH_USER = 'neo4j_auth_user' NEO4J_AUTH_USER = 'neo4j_auth_user'
NEO4J_AUTH_PW = 'neo4j_auth_pw' NEO4J_AUTH_PW = 'neo4j_auth_pw'
NEO4J_MAX_CONN_LIFE_TIME_SEC = 'neo4j_max_conn_life_time_sec'
DEFAULT_CONFIG = ConfigFactory.from_dict({NEO4J_MAX_CONN_LIFE_TIME_SEC: 50, })
def init(self, conf): def init(self, conf):
# type: (ConfigTree) -> None # type: (ConfigTree) -> None
...@@ -26,7 +29,7 @@ class Neo4jExtractor(Extractor): ...@@ -26,7 +29,7 @@ class Neo4jExtractor(Extractor):
Establish connections and import data model class if provided Establish connections and import data model class if provided
:param conf: :param conf:
""" """
self.conf = conf self.conf = conf.with_fallback(Neo4jExtractor.DEFAULT_CONFIG)
self.graph_url = conf.get_string(Neo4jExtractor.GRAPH_URL_CONFIG_KEY) self.graph_url = conf.get_string(Neo4jExtractor.GRAPH_URL_CONFIG_KEY)
self.cypher_query = conf.get_string(Neo4jExtractor.CYPHER_QUERY_CONFIG_KEY) self.cypher_query = conf.get_string(Neo4jExtractor.CYPHER_QUERY_CONFIG_KEY)
self.driver = self._get_driver() self.driver = self._get_driver()
...@@ -55,6 +58,8 @@ class Neo4jExtractor(Extractor): ...@@ -55,6 +58,8 @@ class Neo4jExtractor(Extractor):
Create a Neo4j connection to Database Create a Neo4j connection to Database
""" """
return GraphDatabase.driver(self.graph_url, return GraphDatabase.driver(self.graph_url,
max_connection_life_time=self.conf.get_int(
Neo4jExtractor.NEO4J_MAX_CONN_LIFE_TIME_SEC),
auth=(self.conf.get_string(Neo4jExtractor.NEO4J_AUTH_USER), auth=(self.conf.get_string(Neo4jExtractor.NEO4J_AUTH_USER),
self.conf.get_string(Neo4jExtractor.NEO4J_AUTH_PW))) self.conf.get_string(Neo4jExtractor.NEO4J_AUTH_PW)))
......
...@@ -128,7 +128,7 @@ class Neo4jCsvPublisher(Publisher): ...@@ -128,7 +128,7 @@ class Neo4jCsvPublisher(Publisher):
self._driver = \ self._driver = \
GraphDatabase.driver(conf.get_string(NEO4J_END_POINT_KEY), GraphDatabase.driver(conf.get_string(NEO4J_END_POINT_KEY),
max_connection_life_time=50, max_connection_life_time=conf.get_int(NEO4J_MAX_CONN_LIFE_TIME_SEC),
auth=(conf.get_string(NEO4J_USER), conf.get_string(NEO4J_PASSWORD))) auth=(conf.get_string(NEO4J_USER), conf.get_string(NEO4J_PASSWORD)))
self._transaction_size = conf.get_int(NEO4J_TRANSCATION_SIZE) self._transaction_size = conf.get_int(NEO4J_TRANSCATION_SIZE)
self._session = self._driver.session() self._session = self._driver.session()
...@@ -410,7 +410,6 @@ ON MATCH SET {update_prop_body}""".format(create_prop_body=create_prop_body, ...@@ -410,7 +410,6 @@ ON MATCH SET {update_prop_body}""".format(create_prop_body=create_prop_body,
:param expect_result: By having this True, it will validate if result object is not None. :param expect_result: By having this True, it will validate if result object is not None.
:return: :return:
""" """
LOGGER.info('Executing statement: {} with params {}'.format(stmt, params))
try: try:
if LOGGER.isEnabledFor(logging.DEBUG): if LOGGER.isEnabledFor(logging.DEBUG):
LOGGER.debug('Executing statement: {} with params {}'.format(stmt, params)) LOGGER.debug('Executing statement: {} with params {}'.format(stmt, params))
......
from setuptools import setup, find_packages from setuptools import setup, find_packages
__version__ = '1.2.8' __version__ = '1.2.9'
setup( setup(
......
Markdown is supported
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