History imports: parsers, import jobs and the import worker
CI / validate-monitoring (push) Successful in 7s
CI / lint (push) Successful in 10s
CI / test (push) Successful in 41s
CI / python-package (push) Skipped
CI / assets (push) Successful in 8s
CI / images (push) Successful in 28s
CI / notify (push) Successful in 7s

- Import jobs (import_jobs table): uploaded exports stored gzipped,
  processed by `flask imports worker`, which claims jobs with
  SKIP LOCKED, inserts in chunks with progress, supports cancelling and
  re-queues jobs whose worker died
- CSV: lastfm-to-csv (no header) or any header-labelled CSV/TSV with
  comma, semicolon or tab delimiters; several date formats and Unix
  seconds/milliseconds
- JSON: pages of user.getRecentTracks (e.g. lastfm.ghan.nl), a single
  recenttracks response, or a flat list; gzipped files accepted
- Last.fm API pull (only when LASTFM_API_KEY is set): pages through
  user.getRecentTracks up to the job's creation time, rate limited,
  with retries and resume
- Imports keep plays older than 14 days, skip empty/future ones and
  dedupe against existing history
- Import metrics and pending/running job gauges

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
mattandClaude Opus 5.5 committed 2026-09-25 15:02:31 +01:00
1 parent e29abe05dd
commit 6fc9d91fa2
9 files changed
+1004 -1

No files matched your search

+19
View File
@@ -97,6 +97,24 @@ registrations_total = Counter(
"User registrations",
)
# History imports (counted by the import worker)
imports_total = Counter(
"scrobbler_imports_total",
"Import jobs by source and lifecycle event (created, completed, failed, cancelled)",
["source", "status"],
)
imported_scrobbles_total = Counter(
"scrobbler_imported_scrobbles_total",
"Rows read by imports, by outcome",
["source", "result"],
)
import_duration_seconds = Histogram(
"scrobbler_import_duration_seconds",
"Time to process an import job",
["source"],
buckets=(1, 5, 15, 30, 60, 120, 300, 600, 1800, 3600, 7200),
)
# Database
db_query_duration_seconds = Histogram(
"scrobbler_db_query_duration_seconds",
@@ -124,4 +142,5 @@ COLLECTED = {
"users": "scrobbler_users",
"active_users": "scrobbler_active_users",
"now_playing_active": "scrobbler_now_playing_active",
"import_jobs": "scrobbler_import_jobs",
}
+20 -1
View File
@@ -38,7 +38,20 @@ class DatabaseStatsCollector(Collector):
now_playing = conn.execute(
text("SELECT count(*) FROM now_playing WHERE expires_at > now()")
).scalar_one()
return {"users": users, "active": active, "now_playing": now_playing}
import_jobs = dict(
conn.execute(
text(
"SELECT status, count(*) FROM import_jobs "
"WHERE status IN ('pending', 'running') GROUP BY status"
)
).all()
)
return {
"users": users,
"active": active,
"now_playing": now_playing,
"import_jobs": {s: import_jobs.get(s, 0) for s in ("pending", "running")},
}
def values(self) -> dict | None:
with self._lock:
@@ -66,3 +79,9 @@ class DatabaseStatsCollector(Collector):
"Users currently playing a track",
value=values["now_playing"],
)
jobs = GaugeMetricFamily(
COLLECTED["import_jobs"], "Import jobs waiting or in progress", labels=["status"]
)
for status, count in values["import_jobs"].items():
jobs.add_metric([status], count)
yield jobs