mirror of
https://git.sr.ht/~phw/scotty
synced 2025-07-01 07:41:57 +02:00
Introduced Backend.Close method
This allows Backend implementations to free used resources. Currently used for musicbrainzws2.Client
This commit is contained in:
parent
c1a480a1a6
commit
499786cab9
14 changed files with 45 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue