2019-02-09 19:42:36 +04:00
|
|
|
import logging
|
|
|
|
|
2023-11-25 00:08:22 +01:00
|
|
|
from sqlmodel import Session, select
|
2019-02-09 19:42:36 +04:00
|
|
|
from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
|
|
|
|
|
2024-03-02 05:01:59 -05:00
|
|
|
from app.core.db import engine
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
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),
|
|
|
|
)
|
:recycle: Refactor backend, settings, DB sessions, types, configs, plugins (#158)
* :recycle: Refactor backend, update DB session handling
* :sparkles: Add mypy config and plugins
* :heavy_plus_sign: Use Python-jose instead of PyJWT
as it has some extra functionalities and features
* :sparkles: Add/update scripts for test, lint, format
* :wrench: Update lint and format configs
* :art: Update import format, comments, and types
* :art: Add types to config
* :sparkles: Add types for all the code, and small fixes
* :art: Use global imports to simplify exploring with Jupyter
* :recycle: Import schemas and models, instead of each class
* :truck: Rename db_session to db for simplicity
* :pushpin: Update dependencies installation for testing
2020-04-20 19:03:13 +02:00
|
|
|
def init() -> None:
|
2019-03-11 13:36:42 +04:00
|
|
|
try:
|
2023-11-25 00:08:22 +01:00
|
|
|
with Session(engine) as session:
|
|
|
|
# Try to create session to check if DB is awake
|
|
|
|
session.exec(select(1))
|
2019-03-11 13:36:42 +04:00
|
|
|
except Exception as e:
|
|
|
|
logger.error(e)
|
|
|
|
raise e
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
|
:recycle: Refactor backend, settings, DB sessions, types, configs, plugins (#158)
* :recycle: Refactor backend, update DB session handling
* :sparkles: Add mypy config and plugins
* :heavy_plus_sign: Use Python-jose instead of PyJWT
as it has some extra functionalities and features
* :sparkles: Add/update scripts for test, lint, format
* :wrench: Update lint and format configs
* :art: Update import format, comments, and types
* :art: Add types to config
* :sparkles: Add types for all the code, and small fixes
* :art: Use global imports to simplify exploring with Jupyter
* :recycle: Import schemas and models, instead of each class
* :truck: Rename db_session to db for simplicity
* :pushpin: Update dependencies installation for testing
2020-04-20 19:03:13 +02:00
|
|
|
def main() -> None:
|
2019-02-09 19:42:36 +04:00
|
|
|
logger.info("Initializing service")
|
|
|
|
init()
|
|
|
|
logger.info("Service finished initializing")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|