CoolFace
Apppublic

vishalbhat07/ctfd

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
ping.py36 linesDownload Raw Back to root
1"""2Script for checking that a database server is available.3Essentially a cross-platform, database agnostic mysqladmin.4"""5import time6 7from sqlalchemy import create_engine8from sqlalchemy.engine.url import make_url9 10from CTFd.config import Config11 12url = make_url(Config.DATABASE_URL)13 14# Ignore sqlite databases15if url.drivername.startswith("sqlite"):16    exit(0)17 18# Null out the database so raw_connection doesnt error if it doesnt exist19# CTFd will create the database if it doesnt exist20url = url._replace(database=None)21 22# Wait for the database server to be available23engine = create_engine(url)24print(f"Waiting for {url.host} to be ready")25while True:26    try:27        engine.raw_connection()28        break29    except Exception as e:30        print(e)31        print("Waiting 1s for database connection")32        time.sleep(1)33 34print(f"{url.host} is ready")35time.sleep(1)36