46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
from django.utils.dateparse import parse_date
|
|
|
|
from apps.ingestion.services.daily_orchestration import run_daily_orchestration
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Run daily HoopScout v2 workflow: extract snapshots, then import snapshots."
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
"--snapshot-date",
|
|
dest="snapshot_date",
|
|
default=None,
|
|
help="Override snapshot date for all extractor outputs (YYYY-MM-DD).",
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
snapshot_date = None
|
|
if options["snapshot_date"]:
|
|
snapshot_date = parse_date(options["snapshot_date"])
|
|
if snapshot_date is None:
|
|
raise CommandError("--snapshot-date must be YYYY-MM-DD.")
|
|
|
|
try:
|
|
result = run_daily_orchestration(snapshot_date=snapshot_date)
|
|
except Exception as exc: # noqa: BLE001
|
|
raise CommandError(str(exc)) from exc
|
|
|
|
extractor_summary = ", ".join(
|
|
f"{row.extractor_name}:{row.records_count}" for row in result.extractors_run
|
|
)
|
|
self.stdout.write(
|
|
self.style.SUCCESS(
|
|
"Daily orchestration completed: "
|
|
f"extractors=[{extractor_summary}] "
|
|
f"import_run={result.import_run_id} "
|
|
f"import_status={result.import_status} "
|
|
f"files_processed={result.files_processed} "
|
|
f"rows_upserted={result.rows_upserted} "
|
|
f"rows_failed={result.rows_failed}"
|
|
)
|
|
)
|