Big changes
This commit is contained in:
@@ -20,11 +20,13 @@ import (
|
||||
"github.com/ponzischeme89/memby/server/internal/cache"
|
||||
"github.com/ponzischeme89/memby/server/internal/config"
|
||||
"github.com/ponzischeme89/memby/server/internal/emby"
|
||||
"github.com/ponzischeme89/memby/server/internal/foryou"
|
||||
"github.com/ponzischeme89/memby/server/internal/library"
|
||||
"github.com/ponzischeme89/memby/server/internal/logging"
|
||||
"github.com/ponzischeme89/memby/server/internal/recommend"
|
||||
"github.com/ponzischeme89/memby/server/internal/sonarr"
|
||||
"github.com/ponzischeme89/memby/server/internal/store"
|
||||
"github.com/ponzischeme89/memby/server/internal/tracearr"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -41,15 +43,15 @@ func main() {
|
||||
}
|
||||
|
||||
logLevel := logging.ParseLevel(os.Getenv("MEMBY_LOG_LEVEL"))
|
||||
log := logging.New(os.Stdout, logLevel)
|
||||
log, events := logging.NewBuffered(os.Stdout, logLevel, 20_000)
|
||||
|
||||
if err := run(log); err != nil {
|
||||
if err := run(log, events); err != nil {
|
||||
log.Error("fatal", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(log *slog.Logger) error {
|
||||
func run(log *slog.Logger, events *logging.Buffer) error {
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -119,21 +121,54 @@ func run(log *slog.Logger) error {
|
||||
// Candidates come from the imported library when one exists, which keeps the
|
||||
// recommendation rebuild off Emby entirely.
|
||||
recommender.Library = st
|
||||
recommender.Behavior = st
|
||||
var tracearrClient *tracearr.Client
|
||||
if cfg.TracearrURL != "" {
|
||||
tracearrClient = tracearr.New(
|
||||
cfg.TracearrURL,
|
||||
cfg.TracearrAPIKey,
|
||||
cfg.TracearrServerID,
|
||||
cfg.UpstreamTimeout,
|
||||
)
|
||||
recommender.Tracearr = tracearrClient
|
||||
log.Info("tracearr recommendation signals enabled", "url", cfg.TracearrURL)
|
||||
}
|
||||
|
||||
syncer := library.NewSyncer(embyClient, st, emby.Credentials{
|
||||
UserID: cfg.SyncUserID,
|
||||
Token: cfg.SyncAPIKey,
|
||||
DeviceID: "memby-gateway-sync",
|
||||
}, log)
|
||||
var forYouService *foryou.Service
|
||||
if tracearrClient != nil {
|
||||
forYouService = foryou.New(
|
||||
st, tracearrClient, recommender, log,
|
||||
cfg.ForYouMinRebuildAge, cfg.ForYouRefreshInterval,
|
||||
)
|
||||
forYouService.ConfigureHouseholdUsers(embyClient, emby.Credentials{
|
||||
UserID: cfg.SyncUserID, Token: cfg.SyncAPIKey,
|
||||
DeviceID: "memby-for-you-builder", DeviceName: "Memby For You builder",
|
||||
})
|
||||
syncer.SetAfterSync(func() {
|
||||
go func() {
|
||||
rebuildCtx, cancel := context.WithTimeout(context.Background(), cfg.RecommendTimeout)
|
||||
defer cancel()
|
||||
forYouService.MarkAllDirty(rebuildCtx)
|
||||
_ = forYouService.RebuildAll(rebuildCtx, false)
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
server := api.New(cfg, api.Deps{
|
||||
Emby: embyClient,
|
||||
Store: st,
|
||||
Cache: ca,
|
||||
Recommender: recommender,
|
||||
ForYou: forYouService,
|
||||
Sonarr: sonarrClient,
|
||||
Syncer: syncer,
|
||||
Log: log,
|
||||
Events: events,
|
||||
})
|
||||
|
||||
if err := server.LoadMaintenance(ctx); err != nil {
|
||||
@@ -154,6 +189,25 @@ func run(log *slog.Logger) error {
|
||||
}
|
||||
}()
|
||||
}
|
||||
if forYouService != nil {
|
||||
go forYouService.Schedule(
|
||||
ctx,
|
||||
cfg.TracearrSyncInterval,
|
||||
cfg.TracearrFullInterval,
|
||||
cfg.ForYouRefreshInterval,
|
||||
)
|
||||
go func() {
|
||||
importCtx, cancel := context.WithTimeout(ctx, cfg.SyncTimeout)
|
||||
defer cancel()
|
||||
if _, err := forYouService.Import(importCtx, false); err != nil {
|
||||
log.Warn("startup Tracearr import failed", "error", err)
|
||||
return
|
||||
}
|
||||
if err := forYouService.RebuildAll(importCtx, false); err != nil {
|
||||
log.Warn("startup For You rebuild failed", "error", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
go pruneAnalytics(ctx, st, cfg.AnalyticsRetention, log)
|
||||
|
||||
httpServer := &http.Server{
|
||||
@@ -195,7 +249,7 @@ func probeHealth() error {
|
||||
if addr == "" {
|
||||
addr = ":8080"
|
||||
}
|
||||
// ":8080" and "0.0.0.0:8080" both mean "connect to localhost" from in here.
|
||||
// Wildcard listen addresses still mean "connect to localhost" from in here.
|
||||
if idx := strings.LastIndex(addr, ":"); idx >= 0 {
|
||||
addr = "127.0.0.1" + addr[idx:]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user