Skip to content

Commit

Permalink
radio: deprecate StreamerService.Queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Jan 3, 2025
1 parent a1916db commit 88a09f2
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ircbot/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion ircbot/commands_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
12 changes: 6 additions & 6 deletions website/api/php/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -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]

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions website/api/v1/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion website/api/v1/sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions website/public/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions website/public/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewState(
News: newsCache,
Templates: exec,
Manager: cfg.Manager,
Streamer: cfg.Streamer,
Queue: cfg.Queue,
Storage: storage,
Search: search,
}
Expand All @@ -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
}
Expand Down

0 comments on commit 88a09f2

Please sign in to comment.