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_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__)
|
||||
|
||||
@ -18,7 +16,17 @@ MAX_RETRIES = 10
|
||||
RETRY_DELAY = 5
|
||||
HEALTHCHECK_INTERVAL = 60
|
||||
|
||||
MYSQL_CONFIG = {
|
||||
_pool_lock = threading.Lock()
|
||||
_connection_pool = None
|
||||
_pool_name = "MySQLPool"
|
||||
_health_thread = None
|
||||
_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,
|
||||
@ -26,12 +34,6 @@ MYSQL_CONFIG = {
|
||||
"connection_timeout": 10
|
||||
}
|
||||
|
||||
_pool_lock = threading.Lock()
|
||||
_connection_pool = None
|
||||
_pool_name = "MySQLPool"
|
||||
_health_thread = None
|
||||
_stop_healthcheck = threading.Event()
|
||||
|
||||
def create_connection_pool(pool_name : str = None):
|
||||
"""
|
||||
Create a MySQL connection pool.
|
||||
@ -42,6 +44,7 @@ def create_connection_pool(pool_name : str = None):
|
||||
Raises:
|
||||
RuntimeError: If pool creation fails after retries.
|
||||
"""
|
||||
MYSQL_CONFIG = get_mysql_config()
|
||||
global _connection_pool, _pool_name
|
||||
if pool_name:
|
||||
_pool_name = pool_name
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user