From 5e2e34ccf0acc360e73c73b9aab266a1946d0c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20=C5=A0imko?= Date: Sat, 25 Jan 2020 23:28:23 +0100 Subject: [PATCH] connection: pessimistic disconnect handling Adds ``pool_pre_ping`` for pessimistic disconnect handling. Helps to reconnect to database from stalled connections from long-running pods. Closes #58. Addresses #133. --- CHANGES.rst | 1 + reana_db/database.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index eefb0c4..53a2aa7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,7 @@ Version 0.8.0 (UNRELEASED) - Adds new disk usage retrieval methods using canonical (bytes) and human-readable (KiB) units. (``User``, ``Workflow``) - Adds new properties ``started_at`` and ``finished_at`` to the ``Job`` model, updated on status change. - Adds ``get_priority`` workflow method, that combines both complexity and concurrency, to pass to the scheduler. +- Adds database connection pool pre-ping to prevent stalled database connections problems. - Changes disk quota calculation functions to allow passing raw bytes to increase the used quota. - Removes support for Python 2. diff --git a/reana_db/database.py b/reana_db/database.py index 18fed66..b8ea732 100644 --- a/reana_db/database.py +++ b/reana_db/database.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of REANA. -# Copyright (C) 2018 CERN. +# Copyright (C) 2018, 2019, 2020, 2021 CERN. # # REANA is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -19,7 +19,7 @@ from reana_db.models import Base # isort:skip # noqa -engine = create_engine(SQLALCHEMY_DATABASE_URI) +engine = create_engine(SQLALCHEMY_DATABASE_URI, pool_pre_ping=False) Session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine)) Base.query = Session.query_property()