mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-25 02:37:22 +02: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
5279f23bc8
commit
be3c271c9c
4 changed files with 10 additions and 11 deletions
|
|
@ -109,7 +109,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() {
|
||||
|
|
|
|||
|
|
@ -431,7 +431,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…
Add table
Add a link
Reference in a new issue