Introduced Backend.Close method

This allows Backend implementations to free used resources.
Currently used for musicbrainzws2.Client
This commit is contained in:
Philipp Wolfer 2025-06-10 08:30:26 +02:00
parent c1a480a1a6
commit 499786cab9
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
14 changed files with 45 additions and 8 deletions

View file

@ -42,11 +42,17 @@ const (
type ListenBrainzArchiveBackend struct {
filePath string
lbClient listenbrainz.Client
mbClient musicbrainzws2.Client
mbClient *musicbrainzws2.Client
}
func (b *ListenBrainzArchiveBackend) Name() string { return "listenbrainz-archive" }
func (b *ListenBrainzArchiveBackend) Close() {
if b.mbClient != nil {
b.mbClient.Close()
}
}
func (b *ListenBrainzArchiveBackend) Options() []models.BackendOption {
return []models.BackendOption{{
Name: "archive-path",
@ -58,7 +64,7 @@ func (b *ListenBrainzArchiveBackend) Options() []models.BackendOption {
func (b *ListenBrainzArchiveBackend) InitConfig(config *config.ServiceConfig) error {
b.filePath = config.GetString("archive-path")
b.lbClient = listenbrainz.NewClient("", version.UserAgent())
b.mbClient = *musicbrainzws2.NewClient(musicbrainzws2.AppInfo{
b.mbClient = musicbrainzws2.NewClient(musicbrainzws2.AppInfo{
Name: version.AppName,
Version: version.AppVersion,
URL: version.AppURL,
@ -191,7 +197,7 @@ func (b *ListenBrainzArchiveBackend) ExportLoves(
if len(batch) >= lovesBatchSize {
// The dump does not contain track metadata. Extend it with additional
// lookups
loves, err := lbapi.ExtendTrackMetadata(ctx, &b.lbClient, &b.mbClient, &batch)
loves, err := lbapi.ExtendTrackMetadata(ctx, &b.lbClient, b.mbClient, &batch)
if err != nil {
p.Export.Abort()
progress <- p
@ -205,7 +211,7 @@ func (b *ListenBrainzArchiveBackend) ExportLoves(
}
}
loves, err := lbapi.ExtendTrackMetadata(ctx, &b.lbClient, &b.mbClient, &batch)
loves, err := lbapi.ExtendTrackMetadata(ctx, &b.lbClient, b.mbClient, &batch)
if err != nil {
p.Export.Abort()
progress <- p