Skip to content

Commit

Permalink
fix: infinite loop when sonarr/radarr queue has over 100 items.
Browse files Browse the repository at this point in the history
  • Loading branch information
clambin committed Nov 16, 2024
1 parent 5a37f8d commit f0d90ee
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions cmd/mediamon/mediamon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ package main
import (
"github.com/clambin/mediamon/v2/internal/cmd/mediamon"
"log/slog"
"net/http"
"os"

_ "net/http/pprof"
)

var version = "change_me"

func main() {
go func() {
_ = http.ListenAndServe(":6060", nil)
}()

mediamon.RootCmd.Version = version
if err := mediamon.RootCmd.Execute(); err != nil {
slog.Error("failed to start", "err", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/collectors/xxxarr/clients/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r Radarr) GetCalendar(ctx context.Context, days int) ([]string, error) {
}

func (r Radarr) GetQueue(ctx context.Context) ([]QueuedItem, error) {
var page int32
page := int32(1)
pageSize := int32(100)

var entries []QueuedItem
Expand Down
6 changes: 3 additions & 3 deletions internal/collectors/xxxarr/clients/radarr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ func TestRadarrGetQueue(t *testing.T) {
var resp = []radarr.GetApiV3QueueResponse{
{
JSON200: &radarr.QueueResourcePagingResource{
Page: constP[int32](0),
Page: constP[int32](1),
PageSize: constP[int32](100),
TotalRecords: constP[int32](2),
Records: &[]radarr.QueueResource{{Title: constP("movie 1"), Size: constP(100.0), Sizeleft: constP(25.0)}},
},
},
{
JSON200: &radarr.QueueResourcePagingResource{
Page: constP[int32](1),
Page: constP[int32](2),
PageSize: constP[int32](100),
TotalRecords: constP[int32](2),
Records: &[]radarr.QueueResource{{Title: constP("movie 2"), Size: constP(100.0), Sizeleft: constP(50.0)}},
},
},
}
return &resp[*params.Page], nil
return &resp[*params.Page-1], nil
}).
Twice()
resp, err := c.GetQueue(ctx)
Expand Down
2 changes: 1 addition & 1 deletion internal/collectors/xxxarr/clients/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s Sonarr) getEpisodeNameFromEpisodeResource(_ context.Context, episode son
}

func (s Sonarr) GetQueue(ctx context.Context) ([]QueuedItem, error) {
var page int32
page := int32(1)
pageSize := int32(100)
trueVar := true
var entries []QueuedItem
Expand Down
6 changes: 3 additions & 3 deletions internal/collectors/xxxarr/clients/sonarr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestSonarrGetQueue(t *testing.T) {
var resp = []sonarr.GetApiV3QueueResponse{
{
JSON200: &sonarr.QueueResourcePagingResource{
Page: constP[int32](0),
Page: constP[int32](1),
PageSize: constP[int32](100),
TotalRecords: constP[int32](2),
Records: &[]sonarr.QueueResource{
Expand All @@ -134,7 +134,7 @@ func TestSonarrGetQueue(t *testing.T) {
},
{
JSON200: &sonarr.QueueResourcePagingResource{
Page: constP[int32](1),
Page: constP[int32](2),
PageSize: constP[int32](100),
TotalRecords: constP[int32](2),
Records: &[]sonarr.QueueResource{
Expand All @@ -152,7 +152,7 @@ func TestSonarrGetQueue(t *testing.T) {
},
},
}
return &resp[*params.Page], nil
return &resp[*params.Page-1], nil
}).
Twice()
resp, err := c.GetQueue(ctx)
Expand Down

0 comments on commit f0d90ee

Please sign in to comment.