Skip to content

Commit 0bcf84c

Browse files
committed
log exceptions once in failed health check
avoid spamming the "Database is not initialized, ..." message
1 parent 450d624 commit 0bcf84c

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

reflex/model.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def get_engine(url: str | None = None) -> sqlalchemy.engine.Engine:
111111

112112
if not environment.ALEMBIC_CONFIG.get().exists():
113113
console.warn(
114-
"Database is not initialized, run [bold]reflex db init[/bold] first."
114+
"Database is not initialized, run [bold]reflex db init[/bold] first.",
115+
dedupe=True,
115116
)
116117
_ENGINE[url] = sqlalchemy.engine.create_engine(
117118
url,
@@ -153,7 +154,8 @@ def get_async_engine(url: str | None) -> sqlalchemy.ext.asyncio.AsyncEngine:
153154

154155
if not environment.ALEMBIC_CONFIG.get().exists():
155156
console.warn(
156-
"Database is not initialized, run [bold]reflex db init[/bold] first."
157+
"Database is not initialized, run [bold]reflex db init[/bold] first.",
158+
dedupe=True,
157159
)
158160
_ASYNC_ENGINE[url] = sqlalchemy.ext.asyncio.create_async_engine(
159161
url,
@@ -316,8 +318,12 @@ def get_db_status() -> dict[str, bool]:
316318
engine = get_engine()
317319
with engine.connect() as connection:
318320
connection.execute(sqlalchemy.text("SELECT 1"))
319-
except Exception:
321+
except Exception as exc:
320322
status = False
323+
console.error(
324+
f"Database health check failed: {exc} (subsequent errors will not be logged)",
325+
dedupe=True,
326+
)
321327

322328
return {"db": status}
323329

reflex/utils/prerequisites.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,12 @@ async def get_redis_status() -> dict[str, bool | None]:
440440
await ping_command
441441
else:
442442
status = None
443-
except Exception:
443+
except Exception as exc:
444444
status = False
445+
console.error(
446+
f"Redis health check failed: {exc} (subsequent errors will not be logged)",
447+
dedupe=True,
448+
)
445449

446450
return {"redis": status}
447451

@@ -643,7 +647,8 @@ def check_db_initialized() -> bool:
643647
and not environment.ALEMBIC_CONFIG.get().exists()
644648
):
645649
console.error(
646-
"Database is not initialized. Run [bold]reflex db init[/bold] first."
650+
"Database is not initialized. Run [bold]reflex db init[/bold] first.",
651+
dedupe=True,
647652
)
648653
return False
649654
return True

0 commit comments

Comments
 (0)