Files
full-stack-fastapi-postgresql/{{cookiecutter.project_slug}}/backend/app/app/celeryworker_pre_start.py
Sebastián Ramírez cd112bd683 Refactor/upgrade backend and frontend parts (#2)
* ♻️ Refactor and simplify backend code

* ♻️ Refactor frontend state, integrate typesafe-vuex accessors into state files

* ♻️ Use new state accessors and standardize layout

* 🔒 Upgrade and fix npm security audit

* 🔧 Update local re-generation scripts

* 🔊 Log startup exceptions to detect errors early

* ✏️ Fix password reset token content

* 🔥 Remove unneeded Dockerfile directives

* 🔥 Remove unnecessary print

* 🔥 Remove unnecessary code, upgrade dependencies in backend

* ✏️ Fix typos in docstrings and comments

* 🏗️ Improve user Depends utilities to simplify and remove code

* 🔥 Remove deprecated SQLAlchemy parameter
2019-03-11 13:36:42 +04:00

37 lines
777 B
Python

import logging
from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
from app.db.session import db_session
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
max_tries = 60 * 5 # 5 minutes
wait_seconds = 1
@retry(
stop=stop_after_attempt(max_tries),
wait=wait_fixed(wait_seconds),
before=before_log(logger, logging.INFO),
after=after_log(logger, logging.WARN),
)
def init():
try:
# Try to create session to check if DB is awake
db_session.execute("SELECT 1")
except Exception as e:
logger.error(e)
raise e
def main():
logger.info("Initializing service")
init()
logger.info("Service finished initializing")
if __name__ == "__main__":
main()