def waitForDbConnection(maxTries=0): connected = False retryCount = 0 while not connected: try: db_session.execute("select 1").fetchall() connected = True except sqlalchemy.exc.OperationalError as e: retryCount += 1 db_session.remove() time.sleep(0.1) if maxTries: if retryCount >= maxTries: logging.warning("[Utils] DB connection check unable to " "connect to DB after %s tries." % retryCount) return False if retryCount: logging.warning("[Utils] DB connection check connected to DB after " "%s tries." % retryCount) return True
def shutdown_session(exception=None): db_session.remove()