diff --git a/app.py b/app.py index dda4a7f..7d7bf79 100644 --- a/app.py +++ b/app.py @@ -2,26 +2,6 @@ import psycopg2 from psycopg2 import pool -# Crear un pool de conexiones global -connection_pool = psycopg2.pool.SimpleConnectionPool( - minconn=1, - maxconn=10, # Define el tamaño máximo del pool - dbname=os.getenv("DBNAME"), - user=os.getenv("DBUSER"), - password=os.getenv("DBPASSWORD"), - host=os.getenv("DBHOST"), - port=os.getenv("DBPORT") -) - -def get_db_connection(): - """Obtiene una conexión del pool""" - return connection_pool.getconn() - -def release_db_connection(conn): - """Libera una conexión y la devuelve al pool""" - connection_pool.putconn(conn) - - from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By @@ -38,6 +18,24 @@ from waitress import serve import pandas as pd from io import StringIO +# Crear un pool de conexiones global +connection_pool = psycopg2.pool.ThreadedConnectionPool( + minconn=1, + maxconn=10, # Define el tamaño máximo del pool + dbname=os.getenv("DBNAME"), + user=os.getenv("DBUSER"), + password=os.getenv("DBPASSWORD"), + host=os.getenv("DBHOST"), + port=os.getenv("DBPORT") +) + +def get_db_connection(): + """Obtiene una conexión del pool""" + return connection_pool.getconn() + +def release_db_connection(conn): + """Libera una conexión y la devuelve al pool""" + connection_pool.putconn(conn) # Set options for the Chromium browser