Download backend_prestart.py from Housable/LangChain: direct link, hf CLI and curl.
- Browser
- Download file 853 Bytes
-
https://huggingface.co/spaces/Housable/LangChain/resolve/main/backend_prestart.py
- Command line
-
hf download hf://spaces/Housable/LangChain/backend_prestart.py
-
curl -L -o backend_prestart.py https://huggingface.co/spaces/Housable/LangChain/resolve/main/backend_prestart.py
853 Bytes
| import logging | |
| from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed | |
| from app.db.session import SessionLocal | |
| from sqlalchemy.sql import text | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| max_tries = 60 * 5 # 5 minutes | |
| wait_seconds = 1 | |
| def init() -> None: | |
| try: | |
| db = SessionLocal() | |
| # Try to create session to check if DB is awake | |
| db.execute(text("SELECT 1")) | |
| except Exception as e: | |
| logger.error(e) | |
| raise e | |
| def main() -> None: | |
| logger.info("Initializing service") | |
| init() | |
| logger.info("Service finished initializing") | |
| if __name__ == "__main__": | |
| main() |