from loguru import logger from djagitit.tableau import refresh_extracts from ..config import ( QUERY_PATHS, TABLES, SOURCES, WINDOW_LENGTH, TABLEAU_DATASOURCE_IDS, TABLEAU_SITE, ) from ..db import get_rdb from ..db.queries import QueryLoader def run_hypers() -> bool: logger.info("Starting hyper table creation") rdb = get_rdb() ql = QueryLoader() all_ok = True for source in SOURCES: query_path = getattr(QUERY_PATHS, f"{source}_hyper") logger.info(f"Creating {source} hyper table") status = rdb.execute( ql.load( query_path, main_table=TABLES[f"{source}_main"], hyper_table=TABLES[f"{source}_hyper"], window_length=WINDOW_LENGTH, ) ) if not status: logger.error(f"Failed to create {source} hyper table") all_ok = False logger.info("Triggering Tableau extract refresh") refresh_extracts(TABLEAU_DATASOURCE_IDS, TABLEAU_SITE) if all_ok: logger.success("All hyper tables created and Tableau refresh triggered") else: logger.warning("Some hyper tables failed — Tableau refresh still triggered") return all_ok