Fixed environment variables not being available on pod launch
This commit is contained in:
parent
fd51042d0e
commit
ad1968145a
@ -9,8 +9,6 @@ from typing import Generator
|
|||||||
|
|
||||||
db_username = return_credentials("/etc/secrets/db_username")
|
db_username = return_credentials("/etc/secrets/db_username")
|
||||||
db_password = return_credentials("/etc/secrets/db_password")
|
db_password = return_credentials("/etc/secrets/db_password")
|
||||||
db_host = os.getenv("DB_HOST","localhost")
|
|
||||||
db_database = os.getenv("DB_DATABASE","app")
|
|
||||||
|
|
||||||
logger = setup_logger(__name__)
|
logger = setup_logger(__name__)
|
||||||
|
|
||||||
@ -18,20 +16,24 @@ MAX_RETRIES = 10
|
|||||||
RETRY_DELAY = 5
|
RETRY_DELAY = 5
|
||||||
HEALTHCHECK_INTERVAL = 60
|
HEALTHCHECK_INTERVAL = 60
|
||||||
|
|
||||||
MYSQL_CONFIG = {
|
|
||||||
"host": db_host,
|
|
||||||
"user": db_username,
|
|
||||||
"password": db_password,
|
|
||||||
"database": db_database,
|
|
||||||
"connection_timeout": 10
|
|
||||||
}
|
|
||||||
|
|
||||||
_pool_lock = threading.Lock()
|
_pool_lock = threading.Lock()
|
||||||
_connection_pool = None
|
_connection_pool = None
|
||||||
_pool_name = "MySQLPool"
|
_pool_name = "MySQLPool"
|
||||||
_health_thread = None
|
_health_thread = None
|
||||||
_stop_healthcheck = threading.Event()
|
_stop_healthcheck = threading.Event()
|
||||||
|
|
||||||
|
def get_mysql_config():
|
||||||
|
"""Returns a MYSQL config because creating it on module import lead to the environment variable not being available"""
|
||||||
|
db_host = os.getenv("DB_HOST", "localhost")
|
||||||
|
db_database = os.getenv("DB_DATABASE","app")
|
||||||
|
return {
|
||||||
|
"host": db_host,
|
||||||
|
"user": db_username,
|
||||||
|
"password": db_password,
|
||||||
|
"database": db_database,
|
||||||
|
"connection_timeout": 10
|
||||||
|
}
|
||||||
|
|
||||||
def create_connection_pool(pool_name : str = None):
|
def create_connection_pool(pool_name : str = None):
|
||||||
"""
|
"""
|
||||||
Create a MySQL connection pool.
|
Create a MySQL connection pool.
|
||||||
@ -42,6 +44,7 @@ def create_connection_pool(pool_name : str = None):
|
|||||||
Raises:
|
Raises:
|
||||||
RuntimeError: If pool creation fails after retries.
|
RuntimeError: If pool creation fails after retries.
|
||||||
"""
|
"""
|
||||||
|
MYSQL_CONFIG = get_mysql_config()
|
||||||
global _connection_pool, _pool_name
|
global _connection_pool, _pool_name
|
||||||
if pool_name:
|
if pool_name:
|
||||||
_pool_name = pool_name
|
_pool_name = pool_name
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user