Spaces:
Runtime error
Runtime error
database changes
Browse files- app/database/connection.py +17 -4
- app/graph.py +1 -1
app/database/connection.py
CHANGED
|
@@ -5,27 +5,40 @@ from psycopg_pool import ConnectionPool
|
|
| 5 |
from contextlib import contextmanager
|
| 6 |
|
| 7 |
|
| 8 |
-
|
| 9 |
DB_URL_FOR_CHECKPOINTER_STORE=settings.DB_URL_FOR_CHECKPOINTER_STORE
|
| 10 |
|
|
|
|
| 11 |
pool = ConnectionPool(
|
| 12 |
-
conninfo=DB_URL_FOR_CHECKPOINTER_STORE,
|
| 13 |
-
min_size=1,
|
| 14 |
max_size=10,
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
)
|
| 17 |
|
|
|
|
|
|
|
| 18 |
|
| 19 |
DB_URL_FOR_SQL_AL=settings.DB_URL_FOR_SQL_AL
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
engine = create_engine(
|
| 22 |
DB_URL_FOR_SQL_AL,
|
| 23 |
pool_pre_ping=True,
|
| 24 |
pool_recycle=300
|
| 25 |
)
|
| 26 |
|
|
|
|
|
|
|
|
|
|
| 27 |
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False)
|
| 28 |
|
|
|
|
|
|
|
| 29 |
|
| 30 |
def get_session():
|
| 31 |
db = SessionLocal()
|
|
|
|
| 5 |
from contextlib import contextmanager
|
| 6 |
|
| 7 |
|
|
|
|
| 8 |
DB_URL_FOR_CHECKPOINTER_STORE=settings.DB_URL_FOR_CHECKPOINTER_STORE
|
| 9 |
|
| 10 |
+
|
| 11 |
pool = ConnectionPool(
|
| 12 |
+
conninfo=DB_URL_FOR_CHECKPOINTER_STORE,
|
| 13 |
+
min_size=1,
|
| 14 |
max_size=10,
|
| 15 |
+
check=ConnectionPool.check_connection,
|
| 16 |
+
max_idle=300,
|
| 17 |
+
kwargs={"autocommit": True,"sslmode": "require"}
|
| 18 |
)
|
| 19 |
|
| 20 |
+
# sslmode=require means that our application will only connect to the database if a secure, encrypted connection can be established.
|
| 21 |
+
|
| 22 |
|
| 23 |
DB_URL_FOR_SQL_AL=settings.DB_URL_FOR_SQL_AL
|
| 24 |
|
| 25 |
+
|
| 26 |
+
# pool_pre_ping=True: It checks if a connection is still alive before using it. If it's dead, it recycles it so the app doesn't crash.
|
| 27 |
+
# pool_recycle=300: It closes and recreates connections every 5 minutes (300 seconds) to prevent stale connections.
|
| 28 |
+
|
| 29 |
engine = create_engine(
|
| 30 |
DB_URL_FOR_SQL_AL,
|
| 31 |
pool_pre_ping=True,
|
| 32 |
pool_recycle=300
|
| 33 |
)
|
| 34 |
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# This is a factory that generates individual database sessions
|
| 38 |
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False)
|
| 39 |
|
| 40 |
+
# This creates a session factory. We set autoflush=False and autocommit=False because we want manual control over when data is saved (committed) to the database, which prevents accidental or premature changes.
|
| 41 |
+
|
| 42 |
|
| 43 |
def get_session():
|
| 44 |
db = SessionLocal()
|
app/graph.py
CHANGED
|
@@ -39,7 +39,7 @@ tool_node_retry_policy = RetryPolicy(
|
|
| 39 |
)
|
| 40 |
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
# Nodes
|
| 45 |
builder = StateGraph(EmailAgentState)
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
|
| 42 |
+
|
| 43 |
|
| 44 |
# Nodes
|
| 45 |
builder = StateGraph(EmailAgentState)
|