Skip to content

Commit d5d1e59

Browse files
committed
fixed event loops issue
1 parent 19de601 commit d5d1e59

File tree

2 files changed

+301
-296
lines changed

2 files changed

+301
-296
lines changed

07_uns_graphql/src/uns_graphql/backend/graphdb.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import logging
2323

2424
from neo4j import AsyncDriver, AsyncGraphDatabase, Record
25+
from neo4j.exceptions import Neo4jError
2526

2627
from uns_graphql.graphql_config import GraphDBConfig
2728

@@ -58,15 +59,18 @@ async def get_graphdb_driver(cls, retry: int = 0) -> AsyncDriver:
5859
AsyncDriver: The Neo4j async driver.
5960
"""
6061
LOGGER.debug("GraphDB driver requested")
61-
if cls._graphdb_driver is None:
62-
LOGGER.info("Creating a new GraphDB driver")
63-
cls._graphdb_driver = AsyncGraphDatabase.driver(
64-
uri=GraphDBConfig.conn_url, auth=(GraphDBConfig.user, GraphDBConfig.password), database=GraphDBConfig.database
65-
)
6662
try:
63+
if cls._graphdb_driver is None:
64+
LOGGER.info("Creating a new GraphDB driver")
65+
cls._graphdb_driver = AsyncGraphDatabase.driver(
66+
uri=GraphDBConfig.conn_url,
67+
auth=(GraphDBConfig.user, GraphDBConfig.password),
68+
database=GraphDBConfig.database,
69+
)
70+
6771
await cls._graphdb_driver.verify_connectivity()
6872
LOGGER.debug("GraphDB driver connectivity verified")
69-
except Exception as ex:
73+
except Neo4jError as ex:
7074
LOGGER.error("Failed to verify GraphDB driver connectivity: %s", str(ex), stack_info=True, exc_info=True)
7175
# In case of connectivity failure, close the existing driver and create a new one
7276
await cls.release_graphdb_driver()
@@ -91,7 +95,7 @@ async def release_graphdb_driver(cls):
9195
try:
9296
await cls._graphdb_driver.close()
9397
LOGGER.info("GraphDB driver closed successfully")
94-
except Exception as ex:
98+
except Neo4jError as ex:
9599
LOGGER.error("Error closing the GraphDB driver: %s", str(ex), stack_info=True, exc_info=True)
96100
finally:
97101
cls._graphdb_driver = None

0 commit comments

Comments
 (0)