Enrich MonitorAlbum response, prevent duplicate downloads, recover orphaned jobs on startup

This commit is contained in:
Alexander
2026-05-09 20:01:53 +02:00
parent 5257ed0f1b
commit cca404bcc0
5 changed files with 133 additions and 7 deletions
+30
View File
@@ -115,6 +115,36 @@ func (w *PollDownloadWorker) reschedule(ctx context.Context, args PollDownloadAr
return nil
}
func (w *PollDownloadWorker) RecoverOrphanedDownloads(ctx context.Context) {
active, err := w.Downloads.GetActive(ctx)
if err != nil {
log.Error().Err(err).Msg("failed to query active downloads for recovery")
return
}
if len(active) == 0 {
return
}
for _, d := range active {
_, err := w.RiverClient.Insert(ctx, PollDownloadArgs{
DownloadID: d.ID,
TorrentHash: d.QbitHash,
CheckInterval: 30 * time.Second,
}, &river.InsertOpts{
ScheduledAt: time.Now().Add(5 * time.Second),
UniqueOpts: river.UniqueOpts{
ByArgs: true,
},
})
if err != nil {
log.Error().Err(err).Str("download_id", d.ID).Msg("failed to reschedule orphaned download")
} else {
log.Info().Str("download_id", d.ID).Str("hash", d.QbitHash).Msg("recovered orphaned download poll job")
}
}
}
var audioExtensions = map[string]bool{
".flac": true, ".mp3": true, ".aac": true, ".m4a": true,
".ape": true, ".wv": true, ".ogg": true, ".wav": true, ".alac": true,