From 88a09f23d6ca211ba0215a92eb1d5886aa4d2980 Mon Sep 17 00:00:00 2001 From: Wessie Date: Fri, 3 Jan 2025 19:44:36 +0100 Subject: [PATCH] radio: deprecate StreamerService.Queue --- ircbot/api.go | 2 +- ircbot/commands_impl.go | 2 +- radio.go | 1 + website/api/php/api.go | 12 ++++++------ website/api/v1/router.go | 2 ++ website/api/v1/sse.go | 2 +- website/public/home.go | 4 ++-- website/public/state.go | 4 ++-- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ircbot/api.go b/ircbot/api.go index ae5593c6..4e429c7f 100644 --- a/ircbot/api.go +++ b/ircbot/api.go @@ -209,7 +209,7 @@ func (ann *announceService) AnnounceRequest(ctx context.Context, song radio.Song message := "Requested:{green} '%s'" // Get queue from streamer - songQueue, err := ann.bot.Streamer.Queue(ctx) + songQueue, err := ann.bot.Queue.Entries(ctx) if err != nil { return errors.E(op, err) } diff --git a/ircbot/commands_impl.go b/ircbot/commands_impl.go index 55b1fada..791eafc3 100644 --- a/ircbot/commands_impl.go +++ b/ircbot/commands_impl.go @@ -148,7 +148,7 @@ func StreamerQueueLength(e Event) error { message := "There are %d requests (%s), %d randoms (%s), total of %d songs (%s)" // Get queue from streamer - songQueue, err := e.Bot.Streamer.Queue(e.Ctx) + songQueue, err := e.Bot.Queue.Entries(e.Ctx) if err != nil { return errors.E(op, err) } diff --git a/radio.go b/radio.go index f69a5984..38be3a9a 100644 --- a/radio.go +++ b/radio.go @@ -443,6 +443,7 @@ type StreamerService interface { Stop(ctx context.Context, force bool) error RequestSong(context.Context, Song, string) error + // Deprecated: use QueueService Queue(context.Context) (Queue, error) } diff --git a/website/api/php/api.go b/website/api/php/api.go index 1f74a98e..02f65536 100644 --- a/website/api/php/api.go +++ b/website/api/php/api.go @@ -30,7 +30,7 @@ import ( func NewAPI(ctx context.Context, cfg config.Config, storage radio.StorageService, statusValue *util.Value[radio.Status]) (*API, error) { - status, err := newV0Status(ctx, storage, cfg.Streamer, statusValue) + status, err := newV0Status(ctx, storage, cfg.Queue, statusValue) if err != nil { return nil, err } @@ -400,11 +400,11 @@ func (a *API) postRequest(w http.ResponseWriter, r *http.Request) { } func newV0Status(ctx context.Context, storage radio.SongStorageService, - streamer radio.StreamerService, status *util.Value[radio.Status]) (*v0Status, error) { + queue radio.QueueService, status *util.Value[radio.Status]) (*v0Status, error) { s := v0Status{ songs: storage, - streamer: streamer, + queue: queue, status: status, updatePeriod: time.Second * 2, longUpdatePeriod: time.Second * 10, @@ -428,8 +428,8 @@ func newV0Status(ctx context.Context, storage radio.SongStorageService, type v0Status struct { // song storage to get last played songs songs radio.SongStorageService - // streamer for queue contents - streamer radio.StreamerService + // queue for queue contents + queue radio.QueueService // status value status *util.Value[radio.Status] @@ -536,7 +536,7 @@ func (s *v0Status) createStatusJSON(ctx context.Context) (v0StatusJSON, error) { if last.ListCreatedOn.IsZero() || now.Sub(last.ListCreatedOn) < s.longUpdatePeriod { - q, err := s.streamer.Queue(ctx) + q, err := s.queue.Entries(ctx) if err != nil { return last, err } diff --git a/website/api/v1/router.go b/website/api/v1/router.go index 6b372360..b5edfb16 100644 --- a/website/api/v1/router.go +++ b/website/api/v1/router.go @@ -39,6 +39,7 @@ func NewAPI(ctx context.Context, cfg config.Config, sse: NewStream(templates), manager: cfg.Manager, streamer: cfg.Streamer, + queue: cfg.Queue, storage: sg, songSecret: songSecret, fs: fs, @@ -58,6 +59,7 @@ type API struct { sse *Stream manager radio.ManagerService streamer radio.StreamerService + queue radio.QueueService storage radio.StorageService songSecret secret.Secret fs afero.Fs diff --git a/website/api/v1/sse.go b/website/api/v1/sse.go index d709352d..fe030c0c 100644 --- a/website/api/v1/sse.go +++ b/website/api/v1/sse.go @@ -83,7 +83,7 @@ func (a *API) runStatusUpdates(ctx context.Context) { } func (a *API) sendQueue(ctx context.Context) { - q, err := a.streamer.Queue(ctx) + q, err := a.queue.Entries(ctx) if err != nil { zerolog.Ctx(ctx).Error().Err(err).Str("sse", "queue").Msg("") return diff --git a/website/public/home.go b/website/public/home.go index b1b2cfa6..5ccff7f1 100644 --- a/website/public/home.go +++ b/website/public/home.go @@ -35,13 +35,13 @@ func (s State) GetHome(w http.ResponseWriter, r *http.Request) { } } -func (s State) getHome(w http.ResponseWriter, r *http.Request) error { +func (s *State) getHome(w http.ResponseWriter, r *http.Request) error { const op errors.Op = "website/public.getHome" input := NewHomeInput(r) ctx := r.Context() - queue, err := s.Streamer.Queue(ctx) + queue, err := s.Queue.Entries(ctx) if err != nil { hlog.FromRequest(r).Error().Err(err).Msg("streamer queue unavailable") // continue with an empty queue instead diff --git a/website/public/state.go b/website/public/state.go index f909a4a3..2aa45135 100644 --- a/website/public/state.go +++ b/website/public/state.go @@ -28,7 +28,7 @@ func NewState( News: newsCache, Templates: exec, Manager: cfg.Manager, - Streamer: cfg.Streamer, + Queue: cfg.Queue, Storage: storage, Search: search, } @@ -41,7 +41,7 @@ type State struct { News *shared.NewsCache Templates templates.Executor Manager radio.ManagerService - Streamer radio.StreamerService + Queue radio.QueueService Storage radio.StorageService Search radio.SearchService }