|
1 | 1 | """Command-line interface for A4D pipeline.""" |
2 | 2 |
|
3 | 3 | import warnings |
| 4 | +from datetime import datetime |
4 | 5 | from pathlib import Path |
5 | 6 | from typing import Annotated |
6 | 7 |
|
@@ -565,8 +566,10 @@ def run_pipeline_cmd( |
565 | 566 | from a4d.config import settings |
566 | 567 | from a4d.gcp.bigquery import load_pipeline_tables |
567 | 568 | from a4d.gcp.storage import download_tracker_files, upload_output |
| 569 | + from a4d.tables.clinic import create_table_clinic_static |
568 | 570 |
|
569 | 571 | _workers = workers if workers is not None else settings.max_workers |
| 572 | + run_ts = datetime.now().strftime("%Y/%m/%d/%H%M%S") |
570 | 573 |
|
571 | 574 | console.print("\n[bold blue]A4D Full Pipeline[/bold blue]\n") |
572 | 575 | console.print(f"Data root: {settings.data_root}") |
@@ -621,13 +624,30 @@ def run_pipeline_cmd( |
621 | 624 | raise typer.Exit(1) from e |
622 | 625 |
|
623 | 626 | tables_dir = settings.output_root / "tables" |
| 627 | + logs_dir = settings.output_root / "logs" |
624 | 628 |
|
625 | | - # Step 4 – Upload output to GCS |
| 629 | + # Clinic static table — independent of tracker processing, always created |
| 630 | + console.print("[bold]Step 3b/5:[/bold] Creating clinic static table...") |
| 631 | + try: |
| 632 | + create_table_clinic_static(tables_dir) |
| 633 | + console.print(" ✓ Clinic static table created\n") |
| 634 | + except Exception as e: |
| 635 | + console.print(f" [bold red]Error creating clinic static table: {e}[/bold red]\n") |
| 636 | + raise typer.Exit(1) from e |
| 637 | + |
| 638 | + # Step 4 – Upload tables/ and logs/ to GCS under a timestamped prefix |
| 639 | + # Each run gets an isolated path: YYYY/MM/DD/HHMMSS/tables/ and .../logs/ |
| 640 | + # This avoids overwriting previous runs and keeps objectCreator permission sufficient. |
626 | 641 | if not skip_upload: |
627 | 642 | console.print("[bold]Step 4/5:[/bold] Uploading output files to GCS...") |
| 643 | + console.print(f" Prefix: {run_ts}/\n") |
628 | 644 | try: |
629 | | - uploaded = upload_output(source_dir=settings.output_root) |
630 | | - console.print(f" ✓ Uploaded {len(uploaded)} files\n") |
| 645 | + uploaded: list[str] = [] |
| 646 | + if tables_dir.exists(): |
| 647 | + uploaded += upload_output(source_dir=tables_dir, prefix=f"{run_ts}/tables") |
| 648 | + if logs_dir.exists(): |
| 649 | + uploaded += upload_output(source_dir=logs_dir, prefix=f"{run_ts}/logs") |
| 650 | + console.print(f" ✓ Uploaded {len(uploaded)} files to gs://{settings.upload_bucket}/{run_ts}/\n") |
631 | 651 | except Exception as e: |
632 | 652 | console.print(f"\n[bold red]Error during GCS upload: {e}[/bold red]\n") |
633 | 653 | raise typer.Exit(1) from e |
|
0 commit comments