def attempt_database_connection()

in bugbounty_gpt/db/migrate.py [0:0]


def attempt_database_connection(engine):
    """
    Attempts to connect to the database, and initializes the submission table if it does not exist.

    :param engine: The SQLAlchemy engine to use for inspecting the database and running migrations.
    """
    for attempt in range(MAX_ATTEMPTS):
        try:
            check_and_init_submission_table(engine)
            break # Exit the loop if connection is successful
        except OperationalError as e:
            logger.warning(f"Failed to connect to database (attempt {attempt + 1} of {MAX_ATTEMPTS}). Retrying in {WAIT_TIME} seconds...")
            time.sleep(WAIT_TIME)
    else:
        # This block executes if the loop completes without a 'break' statement (i.e., all attempts failed)
        logger.error("Failed to connect to database after all attempts. Exiting.")
        raise Exception("Unable to connect to database")