2.9 KiB
2.9 KiB
Worker & Job Specification
This document defines the background processing architecture using BullMQ. Workers are responsible for CPU-intensive tasks and time-sensitive cleanup.
1. Job Architecture
All jobs are dispatched via the Backend API and processed by specialized Worker containers.
| Job Name | Priority | Responsibility | Trigger |
|---|---|---|---|
metadata_refresh |
Medium | Re-scanning files for tag/metadata changes. | Manual (POST /api/library/reindex) |
artwork_download |
Low | Fetching covers from Cover Art Archive/Discogs. | On metadata enrichment or new file. |
lyrics_download |
Low | Fetching synced lyrics (LRCLib). | On metadata enrichment. |
recommendation_gen |
Low | Calculating new "Vibe" seeds and batching. | On session start or after playback completion. |
audio_analysis |
High | Running essentia for BPM, Key, Energy. |
New file/re-index. |
filesystem_rescan |
High | Reconciling DB with actual disk state. | Scheduled (Daily/Weekly). |
cleanup_sweep |
Medium | Managing the Dislike Lifecycle/Deletion. | Scheduled (Hourly). |
2. Detailed Job Workflows
A. Audio Analysis Pipeline (audio_analysis)
This is the most resource-intensive job.
- Input:
track_id. - Process:
- Spin up
essentiasubprocess. - Extract BPM, Key, Energy, and Melodic features.
- Spin up
- Output: Update
track_audio_featurestable and markaudio_features_ready = true.
B. Metadata Enrichment Pipeline (metadata_refresh / artwork_download)
Triggered when a new file is detected or a re-index occurs.
- Input:
track_id. - Process:
- Lookup
mbidvia MusicBrainz. - Fetch lyrics via LRCLib.
- Fetch artwork via Cover Art Archive.
- Lookup
- Output: Update
tracks,artists, andalbumstables.
C. The "Consistency" Worker (filesystem_rescan)
Ensures the database is an accurate reflection of the disk.
- Process:
- Walk through
/mnt/hdd1/media/Music. - Compare
mtimeandsizeagainst DB. - Action: If a file is missing, set
track.state = 'MISSING'. If a new file is found, triggermetadata_refresh.
- Walk through
D. The "Cleanup" Worker (cleanup_sweep)
Handles the temporal logic of the dislike lifecycle.
- Process:
- Check
dislikeswherestate = 'warned'andwarned_at < now - 24h. - Trigger physical file deletion and DB row removal.
- Check
dislikeswherestate = 'hidden'anddisliked_at < now - 48h. - Trigger
ntfynotification.
- Check
3. Error Handling & Retries
- Exponential Backoff: All external API jobs (MusicBrainz, etc.) must use exponential backoff to respect rate limits.
- Dead Letter Queue (DLQ): Jobs that fail after 5 retries are moved to a DLQ for manual inspection via the Admin Dashboard.
- Idempotency: All jobs must be idempotent. Running
audio_analysistwice on the sametrack_idmust not create duplicate data or errors.