YTShortMakerArchx commited on
Commit
7a85337
Β·
verified Β·
1 Parent(s): 7cf11f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -17
app.py CHANGED
@@ -942,49 +942,55 @@ async def _check_dataset_reachability(repo: str, name: str) -> bool:
942
  async def startup():
943
  global _http, _store
944
 
945
- _http = httpx.AsyncClient(timeout=HTTP_TIMEOUT)
946
-
947
- # ── Check dataset reachability BEFORE creating DatasetStore ──────────────
948
  logger.info("=" * 80)
949
- logger.info("DATASET REACHABILITY CHECK")
950
  logger.info("=" * 80)
951
 
952
  if HF_TOKEN:
953
- logger.info(f"HF_TOKEN: configured (length={len(HF_TOKEN)})")
954
  else:
955
- logger.error("HF_TOKEN: NOT configured")
956
 
957
  if HF_DATASET:
958
- logger.info(f"HF_DATASET (primary): {HF_DATASET}")
959
  dataset1_ok = await _check_dataset_reachability(HF_DATASET, "PRIMARY")
960
  else:
961
- logger.error("HF_DATASET (primary): NOT configured")
962
  dataset1_ok = False
963
 
964
  if HF_DATASET_2:
965
- logger.info(f"HF_DATASET_2 (secondary): {HF_DATASET_2}")
966
  dataset2_ok = await _check_dataset_reachability(HF_DATASET_2, "SECONDARY")
967
  else:
968
- logger.warning("HF_DATASET_2 (secondary): NOT configured - single dataset mode")
969
  dataset2_ok = False
970
 
971
  logger.info("=" * 80)
972
- logger.info(f"PRIMARY dataset ({HF_DATASET}): {'βœ“ READY' if dataset1_ok else 'βœ— UNAVAILABLE'}")
 
 
973
  if HF_DATASET_2:
974
  logger.info(f"SECONDARY dataset ({HF_DATASET_2}): {'βœ“ READY' if dataset2_ok else 'βœ— UNAVAILABLE'}")
 
975
  if dataset1_ok and dataset2_ok:
976
- logger.info("DUAL-DATASET MODE: Both datasets are operational")
977
  elif dataset1_ok:
978
- logger.warning("DUAL-DATASET MODE: Only primary dataset is operational")
979
  elif dataset2_ok:
980
- logger.warning("DUAL-DATASET MODE: Only secondary dataset is operational")
981
  else:
982
- logger.error("DUAL-DATASET MODE: Neither dataset is operational!")
983
  else:
984
- logger.info("SINGLE-DATASET MODE: Only primary dataset configured")
 
985
  logger.info("=" * 80)
986
 
987
- # ── Now create DatasetStore with both repos ───────────────────────────────
 
 
988
  _store = DatasetStore(hf_token=HF_TOKEN, dataset_repo=HF_DATASET, dataset_repo_2=HF_DATASET_2)
989
 
990
  init_tasks = [
@@ -1343,6 +1349,40 @@ async def pipeline_heartbeat(pipeline_id: str):
1343
  return {"pipeline_id": pipeline_id, "acknowledged": True, "stages": stages}
1344
 
1345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1346
  @app.get("/capacity")
1347
  async def get_capacity():
1348
  active_pipelines = [
 
942
  async def startup():
943
  global _http, _store
944
 
945
+ # ══════════════════════════════════════════════════════════════════════════
946
+ # DATASET REACHABILITY CHECK β€” FIRST THING AT STARTUP
947
+ # ══════════════════════════════════════════════════════════════════════════
948
  logger.info("=" * 80)
949
+ logger.info("DATASET REACHABILITY CHECK (at space build/startup)")
950
  logger.info("=" * 80)
951
 
952
  if HF_TOKEN:
953
+ logger.info(f"βœ“ HF_TOKEN: configured (length={len(HF_TOKEN)})")
954
  else:
955
+ logger.error("βœ— HF_TOKEN: NOT configured β€” datasets will not work!")
956
 
957
  if HF_DATASET:
958
+ logger.info(f"βœ“ HF_DATASET (primary) configured: {HF_DATASET}")
959
  dataset1_ok = await _check_dataset_reachability(HF_DATASET, "PRIMARY")
960
  else:
961
+ logger.error("βœ— HF_DATASET (primary): NOT configured β€” no primary dataset!")
962
  dataset1_ok = False
963
 
964
  if HF_DATASET_2:
965
+ logger.info(f"βœ“ HF_DATASET_2 (secondary) configured: {HF_DATASET_2}")
966
  dataset2_ok = await _check_dataset_reachability(HF_DATASET_2, "SECONDARY")
967
  else:
968
+ logger.warning("⚠ HF_DATASET_2 (secondary): NOT configured (will run in single-dataset mode)")
969
  dataset2_ok = False
970
 
971
  logger.info("=" * 80)
972
+ logger.info("DATASET STATUS SUMMARY:")
973
+ logger.info("-" * 80)
974
+ logger.info(f"PRIMARY dataset ({HF_DATASET or 'NOT SET'}): {'βœ“ READY' if dataset1_ok else 'βœ— UNAVAILABLE'}")
975
  if HF_DATASET_2:
976
  logger.info(f"SECONDARY dataset ({HF_DATASET_2}): {'βœ“ READY' if dataset2_ok else 'βœ— UNAVAILABLE'}")
977
+ logger.info("-" * 80)
978
  if dataset1_ok and dataset2_ok:
979
+ logger.info("MODE: βœ“ DUAL-DATASET β€” Both datasets are operational")
980
  elif dataset1_ok:
981
+ logger.warning("MODE: ⚠ DUAL-DATASET (DEGRADED) β€” Only primary dataset is operational")
982
  elif dataset2_ok:
983
+ logger.warning("MODE: ⚠ DUAL-DATASET (DEGRADED) β€” Only secondary dataset is operational")
984
  else:
985
+ logger.error("MODE: βœ— DUAL-DATASET (FAILED) β€” Neither dataset is operational!")
986
  else:
987
+ logger.info("-" * 80)
988
+ logger.info("MODE: βœ“ SINGLE-DATASET β€” Only primary dataset configured")
989
  logger.info("=" * 80)
990
 
991
+ # ── Now initialize HTTP client and DatasetStore ───────────────────────────
992
+ logger.info("Initializing HTTP client and DatasetStore...")
993
+ _http = httpx.AsyncClient(timeout=HTTP_TIMEOUT)
994
  _store = DatasetStore(hf_token=HF_TOKEN, dataset_repo=HF_DATASET, dataset_repo_2=HF_DATASET_2)
995
 
996
  init_tasks = [
 
1349
  return {"pipeline_id": pipeline_id, "acknowledged": True, "stages": stages}
1350
 
1351
 
1352
+ @app.get("/debug/dataset-routing/{pipeline_id}")
1353
+ async def debug_dataset_routing(pipeline_id: str):
1354
+ """Test which dataset a pipeline ID would route to"""
1355
+ if not _store:
1356
+ return {"error": "DatasetStore not initialized"}
1357
+
1358
+ first_hex = pipeline_id[0]
1359
+ hex_value = int(first_hex, 16)
1360
+ is_odd = hex_value % 2 == 1
1361
+
1362
+ repo_1 = _store.repo_1
1363
+ repo_2 = _store.repo_2
1364
+ is_dual = _store._dual
1365
+
1366
+ if is_dual:
1367
+ chosen_repo = repo_2 if is_odd else repo_1
1368
+ mode = "DUAL-DATASET"
1369
+ else:
1370
+ chosen_repo = repo_1
1371
+ mode = "SINGLE-DATASET"
1372
+
1373
+ return {
1374
+ "pipeline_id": pipeline_id,
1375
+ "mode": mode,
1376
+ "first_char": first_hex,
1377
+ "hex_value": hex_value,
1378
+ "is_odd": is_odd,
1379
+ "repo_1": repo_1,
1380
+ "repo_2": repo_2 if repo_2 else "NOT CONFIGURED",
1381
+ "chosen_repo": chosen_repo,
1382
+ "routing": "SECONDARY (repo_2)" if (is_dual and is_odd) else "PRIMARY (repo_1)"
1383
+ }
1384
+
1385
+
1386
  @app.get("/capacity")
1387
  async def get_capacity():
1388
  active_pipelines = [