chore(docker): close neomodel driver on gunicorn worker exit
This commit is contained in:
@@ -34,3 +34,19 @@ def post_worker_init(worker):
|
|||||||
logging.getLogger("library.apps").warning(
|
logging.getLogger("library.apps").warning(
|
||||||
"Startup probe crashed: %s", exc, exc_info=True
|
"Startup probe crashed: %s", exc, exc_info=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def worker_exit(server, worker):
|
||||||
|
# Neomodel lazily creates a neo4j.Driver on first cypher_query and
|
||||||
|
# holds it for the process lifetime. Newer neo4j drivers warn (and
|
||||||
|
# will eventually fail to clean up) if the driver is destroyed
|
||||||
|
# without an explicit close. Close it here so each gunicorn worker
|
||||||
|
# shuts down cleanly.
|
||||||
|
try:
|
||||||
|
from neomodel import db
|
||||||
|
|
||||||
|
db.close_connection()
|
||||||
|
except Exception as exc:
|
||||||
|
logging.getLogger("neomodel").warning(
|
||||||
|
"Failed to close neomodel driver on worker exit: %s", exc
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user