Promote test → main: measurements + measurement-jobs (chat#1796)

Merged
SW
4mo ago
+1613-8

Promote the two merged chat#1796 PRs from test to main (prod).

Includes:

  • #668 — measurement-jobs write resource (POST /research/measurement-jobs, source: current|historical) + card-on-file gate on historical + retryable backfill drain / reclaim.
  • #669 — measurements read collection (GET /research/tracks|albums/{id}/measurements, series + aggregate=run_rate + latest).

Both verified on preview (results in the respective PRs). Additive — legacy endpoints keep serving. After this lands, the catalog-value-estimator seed (skills#43) works against prod.


Summary by cubic

Promotes consolidated research measurement APIs to prod: adds POST /api/research/measurement-jobs for ingest and GET /api/research/tracks|albums/{id}/measurements for reads. Also adds a Songstats card-on-file gate and makes the historical backfill drain retryable with automatic reclaim in maintenance. Legacy endpoints remain available.

  • New Features

    • POST /api/research/measurement-jobs — { scope, source }:
      • source: "current" uses the snapshot pipeline (maps snapshot_id → id).
      • source: "historical" enqueues Songstats backfill ranked by latest counts; skips songs already backfilled; bounded concurrency; returns 202.
      • Validation: auth + research credits; historical requires a payment method; current does not.
    • GET /api/research/tracks/{id}/measurements — daily series; ?aggregate=run_rate over a trailing window. {id} can be ISRC or a Spotify track id (resolved to ISRC).
    • GET /api/research/albums/{id}/measurements — latest count per track (thin remap of playcounts). CORS preflight added for new routes.
  • Reliability

    • Backfill drain: 408/429/5xx are marked failed (reclaimable); 404 and other permanent 4xx are marked done (terminal).
    • Maintenance cron reclaims failed and stale in_progress rows before draining and reports the reclaimed count.

Summary by CodeRabbit

  • New Features

    • Added research measurement endpoints for retrieving album and track playcount data
    • Introduced measurement job creation supporting historical backfills and current snapshots
    • Added measurement aggregation options, including run-rate projections
    • Implemented payment method validation for measurement features
  • Improvements

    • Enhanced error handling with better categorization for failed requests
    • Improved queue management with staleness detection and recovery mechanisms