Enrich MonitorAlbum response, prevent duplicate downloads, recover orphaned jobs on startup
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user