mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-07 02:38:50 +01:00
refactor(plugins): rename GetPlaylists, add NotFound error and RetryInterval
Rename GetPlaylists → GetAvailablePlaylists for clarity. Add PlaylistGeneratorErrorNotFound so plugins can signal a playlist is temporarily unavailable (orchestrator skips it but retries on next discovery). Add RetryInterval on GetAvailablePlaylistsResponse for automatic retry of transient GetPlaylist failures.
This commit is contained in:
parent
a8a336de33
commit
fde4517339
8 changed files with 279 additions and 115 deletions
23
plugins/testdata/test-playlist-generator/main.go
vendored
23
plugins/testdata/test-playlist-generator/main.go
vendored
|
|
@ -3,6 +3,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/navidrome/navidrome/plugins/pdk/go/pdk"
|
||||
pg "github.com/navidrome/navidrome/plugins/pdk/go/playlistgenerator"
|
||||
|
|
@ -14,11 +15,11 @@ func init() {
|
|||
|
||||
type testPlaylistGenerator struct{}
|
||||
|
||||
func (t *testPlaylistGenerator) GetPlaylists(_ pg.GetPlaylistsRequest) (pg.GetPlaylistsResponse, error) {
|
||||
func (t *testPlaylistGenerator) GetAvailablePlaylists(_ pg.GetAvailablePlaylistsRequest) (pg.GetAvailablePlaylistsResponse, error) {
|
||||
// Check for configured error
|
||||
errMsg, hasErr := pdk.GetConfig("error")
|
||||
if hasErr && errMsg != "" {
|
||||
return pg.GetPlaylistsResponse{}, fmt.Errorf("%s", errMsg)
|
||||
return pg.GetAvailablePlaylistsResponse{}, fmt.Errorf("%s", errMsg)
|
||||
}
|
||||
|
||||
// Get the owner username from config (defaults to "admin")
|
||||
|
|
@ -27,19 +28,33 @@ func (t *testPlaylistGenerator) GetPlaylists(_ pg.GetPlaylistsRequest) (pg.GetPl
|
|||
ownerUsername = u
|
||||
}
|
||||
|
||||
return pg.GetPlaylistsResponse{
|
||||
resp := pg.GetAvailablePlaylistsResponse{
|
||||
Playlists: []pg.PlaylistInfo{
|
||||
{ID: "daily-mix-1", OwnerUsername: ownerUsername},
|
||||
{ID: "daily-mix-2", OwnerUsername: ownerUsername},
|
||||
},
|
||||
RefreshInterval: 0, // No re-discovery in tests
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Support configurable retry interval
|
||||
if ri, ok := pdk.GetConfig("retry_interval"); ok && ri != "" {
|
||||
if v, err := strconv.ParseInt(ri, 10, 64); err == nil {
|
||||
resp.RetryInterval = v
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t *testPlaylistGenerator) GetPlaylist(req pg.GetPlaylistRequest) (pg.GetPlaylistResponse, error) {
|
||||
// Check for configured error
|
||||
errMsg, hasErr := pdk.GetConfig("get_playlist_error")
|
||||
if hasErr && errMsg != "" {
|
||||
// Check if the error should be typed (e.g., NotFound)
|
||||
errType, _ := pdk.GetConfig("get_playlist_error_type")
|
||||
if errType == pg.PlaylistGeneratorErrorNotFound.Error() {
|
||||
return pg.GetPlaylistResponse{}, fmt.Errorf("%w: %s", pg.PlaylistGeneratorErrorNotFound, errMsg)
|
||||
}
|
||||
return pg.GetPlaylistResponse{}, fmt.Errorf("%s", errMsg)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue