Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
feat(app): toggle service readiness checks via environment.
Browse files Browse the repository at this point in the history
Closes #219
  • Loading branch information
peterschutt committed Jan 12, 2023
1 parent ca5dc88 commit 76b5928
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# App
BUILD_NUMBER=
CHECK_DB_READY=true
CHECK_REDIS_READY=true
DEBUG=true
ENVIRONMENT=local
NAME=my-starlite-app
Expand Down
8 changes: 5 additions & 3 deletions src/starlite_saqlalchemy/lifespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import starlite
from sqlalchemy import text

from starlite_saqlalchemy import redis
from starlite_saqlalchemy import redis, settings
from starlite_saqlalchemy.db import engine

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -41,5 +41,7 @@ async def _redis_ready() -> None:

async def before_startup_handler(_: starlite.Starlite) -> None:
"""Do things before the app starts up."""
await _db_ready()
await _redis_ready()
if settings.app.CHECK_DB_READY:
await _db_ready()
if settings.app.CHECK_REDIS_READY:
await _redis_ready()
4 changes: 4 additions & 0 deletions src/starlite_saqlalchemy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class Config:

BUILD_NUMBER: str = ""
"""Identifier for CI build."""
CHECK_DB_READY: bool = True
"""Check for database readiness on startup."""
CHECK_REDIS_READY: bool = True
"""Check for redis readiness on startup."""
DEBUG: bool = False
"""Run `Starlite` with `debug=True`."""
ENVIRONMENT: str = "prod"
Expand Down

0 comments on commit 76b5928

Please sign in to comment.