def wait_for_object_table()

in deprecated-code/dags/sample-rideshare-object-table-delay.py [0:0]


def wait_for_object_table():
    # Wait for job to start
    print ("wait_for_object_table STARTED, sleeping for 15 seconds for jobs to start")
    time.sleep(15)
    rowCount = 0


    client = bigquery.Client()
    sql1 = f"CALL BQ.REFRESH_EXTERNAL_METADATA_CACHE('{project_id}.{rideshare_lakehouse_raw}.biglake_rideshare_images');"   
    sql2 = f"SELECT COUNT(*) AS RowCount FROM `{project_id}.{rideshare_lakehouse_raw}.biglake_rideshare_images`;"   
 

    # Run for for so many interations
    counter  = 1
    while (counter < 60):    
        try:
            query_job1 = client.query(sql1)
            query_job2 = client.query(sql2)

            for row in query_job2:
                # Row values can be accessed by field name or index.
                print("RowCount = {}".format(row["RowCount"]))
                rowCount = int(str(row["RowCount"]))

            if rowCount == 0:
                print("Sleeping...")
                time.sleep(15)
            else:
                print("Exiting")
                return True
        except requests.exceptions.RequestException as err:
            print(err)
            raise err
        counter = counter + 1

    errorMessage = "The process (wait_for_object_table) run for too long.  Increase the number of iterations."
    raise Exception(errorMessage)