Trying to make the SQL connections more reliable with threads.
This commit is contained in:
@@ -7,6 +7,7 @@ from app.log import log, logging, logger_reset
|
||||
from sqlalchemy import create_engine, text, Time
|
||||
from sqlalchemy.exc import IntegrityError, OperationalError, ProgrammingError
|
||||
from sqlalchemy.pool import NullPool
|
||||
# from multiprocessing import Pool
|
||||
|
||||
|
||||
db_uri = settings.SQLALCHEMY_DB_URI
|
||||
@@ -31,6 +32,22 @@ engine = create_engine(
|
||||
# NOTE: Switching from READ COMMITTED to READ UNCOMMITTED (or REPEATABLE READ). Testing started 2024-04-23
|
||||
# levels: "REPEATABLE READ" "READ COMMITTED" "READ UNCOMMITTED" "SERIALIZABLE"
|
||||
|
||||
|
||||
# def run_in_process(some_data_record):
|
||||
# with engine.connect() as conn:
|
||||
# conn.execute(text("..."))
|
||||
|
||||
|
||||
# def initializer():
|
||||
# """ensure the parent proc's database connections are not touched
|
||||
# in the new connection pool"""
|
||||
# engine.dispose(close=False)
|
||||
|
||||
|
||||
# with Pool(10, initializer=initializer) as p:
|
||||
# p.map(run_in_process, data)
|
||||
|
||||
|
||||
log.info('DB SQL trying to connect...')
|
||||
db = None
|
||||
try:
|
||||
@@ -1268,7 +1285,7 @@ def redis_lookup_id_random(
|
||||
table_name: str,
|
||||
check_int_id: bool = False,
|
||||
log_lvl: int = logging.INFO, # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
minutes: int = 8, # Expire the Redis key after 8 minutes
|
||||
minutes: int = 30, # Expire the Redis key after 8 minutes
|
||||
reset_rate: int = 10, # 1 in 10 chance of resetting the Redis key
|
||||
) -> str|int|bool|None:
|
||||
log.setLevel(log_lvl)
|
||||
|
||||
Reference in New Issue
Block a user