mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-18 07:30:29 +00:00
refactor(podcast): inject server shutdown context into podcast service
Pass the server root context (ctx) to NewPodcastService so that background download goroutines are tied to the server lifecycle and will be cancelled on shutdown, matching the pattern used by scanner.New. Signed-off-by: ji-ho lee <search5@gmail.com>
This commit is contained in:
parent
3a0eec08b9
commit
e9c04a1fa6
@ -106,7 +106,7 @@ func CreateSubsonicAPIRouter(ctx context.Context) *subsonic.Router {
|
||||
playbackServer := playback.GetInstance(dataStore)
|
||||
lyricsLyrics := lyrics.NewLyrics(dataStore, manager)
|
||||
transcodeDecider := stream.NewTranscodeDecider(dataStore, fFmpeg)
|
||||
podcastService := podcasts.NewPodcastService(dataStore, fFmpeg, broker)
|
||||
podcastService := podcasts.NewPodcastService(ctx, dataStore, fFmpeg, broker)
|
||||
sonicSonic := sonic.New(dataStore, manager, matcherMatcher)
|
||||
router := subsonic.New(dataStore, artworkArtwork, mediaStreamer, archiver, players, provider, modelScanner, broker, playlistsPlaylists, playTracker, share, playbackServer, metricsMetrics, lyricsLyrics, transcodeDecider, podcastService, sonicSonic)
|
||||
return router
|
||||
|
||||
@ -31,13 +31,14 @@ type Podcasts interface {
|
||||
}
|
||||
|
||||
type podcastService struct {
|
||||
ds model.DataStore
|
||||
ff ffmpeg.FFmpeg
|
||||
broker events.Broker
|
||||
rootCtx context.Context
|
||||
ds model.DataStore
|
||||
ff ffmpeg.FFmpeg
|
||||
broker events.Broker
|
||||
}
|
||||
|
||||
func NewPodcastService(ds model.DataStore, ff ffmpeg.FFmpeg, broker events.Broker) Podcasts {
|
||||
return &podcastService{ds: ds, ff: ff, broker: broker}
|
||||
func NewPodcastService(rootCtx context.Context, ds model.DataStore, ff ffmpeg.FFmpeg, broker events.Broker) Podcasts {
|
||||
return &podcastService{rootCtx: rootCtx, ds: ds, ff: ff, broker: broker}
|
||||
}
|
||||
|
||||
// podcastLibraryID returns the ID of the podcast virtual library,
|
||||
@ -153,9 +154,7 @@ func (s *podcastService) DownloadEpisode(ctx context.Context, id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Use context.Background() so the download is not cancelled when the HTTP
|
||||
// request completes. TODO: tie to server shutdown context for graceful termination.
|
||||
go s.doDownload(context.Background(), ep, ch)
|
||||
go s.doDownload(s.rootCtx, ep, ch)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ var _ = Describe("PodcastService", func() {
|
||||
DeferCleanup(mockServer.Close)
|
||||
|
||||
conf.Server.DataFolder = GinkgoT().TempDir()
|
||||
svc = podcasts.NewPodcastService(ds, nil, nil)
|
||||
svc = podcasts.NewPodcastService(ctx, ds, nil, nil)
|
||||
})
|
||||
|
||||
Describe("AddChannel", func() {
|
||||
|
||||
@ -427,7 +427,7 @@ func setupTestDB() {
|
||||
metrics.NewNoopInstance(),
|
||||
lyrics.NewLyrics(ds, nil),
|
||||
decider,
|
||||
podcasts.NewPodcastService(ds, ffmpeg.New(), events.NoopBroker()),
|
||||
podcasts.NewPodcastService(context.Background(), ds, ffmpeg.New(), events.NoopBroker()),
|
||||
nil,
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user