feat: add SyncAll periodic sync pipeline and wire Navidrome client into App
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"naviwatcher/internal/config"
|
||||
"naviwatcher/internal/database"
|
||||
"naviwatcher/internal/musicbrainz"
|
||||
"naviwatcher/internal/navidrome"
|
||||
"naviwatcher/internal/scanner"
|
||||
)
|
||||
|
||||
@@ -20,8 +21,14 @@ type App struct {
|
||||
cfg *config.Config
|
||||
db *database.DB
|
||||
mbClient *musicbrainz.MusicBrainzClient
|
||||
ndClient *navidrome.NavidromeClient
|
||||
}
|
||||
|
||||
// navidromeClientFactory constructs the Navidrome client. It is a package-level
|
||||
// variable (not a direct call to navidrome.NewClient) so tests can inject a stub
|
||||
// without requiring a live Navidrome server for authentication.
|
||||
var navidromeClientFactory = navidrome.NewClient
|
||||
|
||||
const defaultConfigPath = "config.yaml"
|
||||
|
||||
func main() {
|
||||
@@ -76,10 +83,17 @@ func NewApp(ctx context.Context, cfg *config.Config, dbPath string) (*App, error
|
||||
|
||||
log.Printf("MusicBrainz client initialized (user-agent: %s)", cfg.MusicBrainz.UserAgent)
|
||||
|
||||
// Initialize Navidrome client (authenticates immediately; error if auth fails).
|
||||
ndClient, err := navidromeClientFactory(cfg.Navidrome)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize navidrome client: %w", err)
|
||||
}
|
||||
|
||||
return &App{
|
||||
cfg: cfg,
|
||||
db: db,
|
||||
mbClient: mbClient,
|
||||
ndClient: ndClient,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -88,6 +102,10 @@ func (a *App) Close() {
|
||||
if a.mbClient != nil {
|
||||
a.mbClient.Close()
|
||||
}
|
||||
if a.ndClient != nil {
|
||||
// NavidromeClient holds a stateless subsonic client; nothing to close
|
||||
// beyond releasing idle connections tracked by the MusicBrainz client.
|
||||
}
|
||||
if a.db != nil {
|
||||
if err := a.db.Close(); err != nil {
|
||||
log.Printf("Error closing database: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user