From 6c6d8d8829e938dc12a36574833e948e4c6622a4 Mon Sep 17 00:00:00 2001 From: Jack Dallas <3620144+JackDallas@users.noreply.github.com> Date: Sat, 13 Aug 2022 00:55:01 +0100 Subject: [PATCH] Make Arr history update interval configurable --- internal/arr/radarr.go | 5 +++-- internal/arr/sonarr.go | 5 +++-- internal/arr/types.go | 3 +++ internal/config/config.go | 25 +++++++++++++++--------- internal/config/types.go | 6 ++++-- internal/service/arrs_manager_service.go | 2 ++ web/src/pages/Config.svelte | 12 +++++++++--- 7 files changed, 40 insertions(+), 18 deletions(-) diff --git a/internal/arr/radarr.go b/internal/arr/radarr.go index ed2f5b0..84e8aee 100644 --- a/internal/arr/radarr.go +++ b/internal/arr/radarr.go @@ -26,7 +26,7 @@ func (arr *RadarrArr) GetHistory() (radarr.History, error) { arr.LastUpdateCountMutex.Lock() defer arr.LastUpdateCountMutex.Unlock() - if time.Since(arr.LastUpdate) > 30*time.Second || arr.History == nil { + if time.Since(arr.LastUpdate) > time.Duration(arr.Config.ArrHistoryUpdateIntervalSeconds)*time.Second || arr.History == nil { his, err := arr.Client.GetHistory(0, 1000) if err != nil { return radarr.History{}, err @@ -35,9 +35,10 @@ func (arr *RadarrArr) GetHistory() (radarr.History, error) { arr.History = his arr.LastUpdate = time.Now() arr.LastUpdateCount = his.TotalRecords + log.Debugf("[Radarr] [%s]: Updated history, next update in %d seconds", arr.Name, arr.Config.ArrHistoryUpdateIntervalSeconds) } - log.Tracef("Radarr.GetHistory(): Returning from GetHistory") + log.Tracef("[Radarr] [%s]: Returning from GetHistory", arr.Name) return *arr.History, nil } diff --git a/internal/arr/sonarr.go b/internal/arr/sonarr.go index 2f15434..859c9f0 100644 --- a/internal/arr/sonarr.go +++ b/internal/arr/sonarr.go @@ -26,7 +26,7 @@ func (arr *SonarrArr) GetHistory() (sonarr.History, error) { arr.LastUpdateCountMutex.Lock() defer arr.LastUpdateCountMutex.Unlock() - if time.Since(arr.LastUpdate) > 30*time.Second || arr.History == nil { + if time.Since(arr.LastUpdate) > time.Duration(arr.Config.ArrHistoryUpdateIntervalSeconds)*time.Second || arr.History == nil { his, err := arr.Client.GetHistory(0, 1000) if err != nil { return sonarr.History{}, err @@ -35,9 +35,10 @@ func (arr *SonarrArr) GetHistory() (sonarr.History, error) { arr.History = his arr.LastUpdate = time.Now() arr.LastUpdateCount = his.TotalRecords + log.Debugf("[Sonarr] [%s]: Updated history, next update in %d seconds", arr.Name, arr.Config.ArrHistoryUpdateIntervalSeconds) } - log.Tracef("Sonarr.GetHistory(): Returning from GetHistory") + log.Tracef("[Sonarr] [%s]: Returning from GetHistory", arr.Name) return *arr.History, nil } diff --git a/internal/arr/types.go b/internal/arr/types.go index 288f729..88bce18 100644 --- a/internal/arr/types.go +++ b/internal/arr/types.go @@ -5,6 +5,7 @@ import ( "sync" "time" + "github.com/jackdallas/premiumizearr/internal/config" "github.com/jackdallas/premiumizearr/internal/utils" "github.com/jackdallas/premiumizearr/pkg/premiumizeme" "golift.io/starr/radarr" @@ -54,6 +55,7 @@ type SonarrArr struct { LastUpdate time.Time LastUpdateCount int LastUpdateCountMutex sync.Mutex + Config *config.Config } type RadarrArr struct { @@ -66,4 +68,5 @@ type RadarrArr struct { LastUpdate time.Time LastUpdateCount int LastUpdateCountMutex sync.Mutex + Config *config.Config } diff --git a/internal/config/config.go b/internal/config/config.go index 89b0b31..28cf8ed 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -127,6 +127,12 @@ func loadConfigFromDisk(altConfigLocation string) (Config, error) { updated = true } + if configInterface["ArrHistoryUpdateIntervalSeconds"] == nil { + log.Info("ArrHistoryUpdateIntervalSeconds not set, setting to 20") + config.ArrHistoryUpdateIntervalSeconds = 20 + updated = true + } + config.altConfigLocation = altConfigLocation if updated { @@ -154,15 +160,16 @@ func defaultConfig() Config { {Name: "Sonarr", URL: "http://localhost:8989", APIKey: "xxxxxxxxx", Type: Sonarr}, {Name: "Radarr", URL: "http://localhost:7878", APIKey: "xxxxxxxxx", Type: Radarr}, }, - BlackholeDirectory: "", - PollBlackholeDirectory: false, - PollBlackholeIntervalMinutes: 10, - DownloadsDirectory: "", - UnzipDirectory: "", - BindIP: "0.0.0.0", - BindPort: "8182", - WebRoot: "", - SimultaneousDownloads: 5, + BlackholeDirectory: "", + PollBlackholeDirectory: false, + PollBlackholeIntervalMinutes: 10, + DownloadsDirectory: "", + UnzipDirectory: "", + BindIP: "0.0.0.0", + BindPort: "8182", + WebRoot: "", + SimultaneousDownloads: 5, + ArrHistoryUpdateIntervalSeconds: 20, } } diff --git a/internal/config/types.go b/internal/config/types.go index 5b25b6e..b42b3e7 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -8,10 +8,10 @@ var ( ErrFailedToSaveConfig = errors.New("failed to save config") ) -//ArrType enum for Sonarr/Radarr +// ArrType enum for Sonarr/Radarr type ArrType string -//AppCallback - Callback for the app to use +// AppCallback - Callback for the app to use type AppCallback func(oldConfig Config, newConfig Config) const ( @@ -49,4 +49,6 @@ type Config struct { WebRoot string `yaml:"WebRoot" json:"WebRoot"` SimultaneousDownloads int `yaml:"SimultaneousDownloads" json:"SimultaneousDownloads"` + + ArrHistoryUpdateIntervalSeconds int `yaml:"ArrHistoryUpdateIntervalSeconds" json:"ArrHistoryUpdateIntervalSeconds"` } diff --git a/internal/service/arrs_manager_service.go b/internal/service/arrs_manager_service.go index 0fb543d..cfceeec 100644 --- a/internal/service/arrs_manager_service.go +++ b/internal/service/arrs_manager_service.go @@ -37,6 +37,7 @@ func (am *ArrsManagerService) Start() { Client: sonarr.New(c), History: nil, LastUpdate: time.Now(), + Config: am.config, } am.arrs = append(am.arrs, &wrapper) log.Tracef("Added Sonarr arr: %s", arr_config.Name) @@ -47,6 +48,7 @@ func (am *ArrsManagerService) Start() { Client: radarr.New(c), History: nil, LastUpdate: time.Now(), + Config: am.config, } am.arrs = append(am.arrs, &wrapper) log.Tracef("Added Radarr arr: %s", arr_config.Name) diff --git a/web/src/pages/Config.svelte b/web/src/pages/Config.svelte index f209c60..b511be8 100644 --- a/web/src/pages/Config.svelte +++ b/web/src/pages/Config.svelte @@ -7,8 +7,8 @@ Modal, FormGroup, Dropdown, -Form, -Checkbox, + Form, + Checkbox, } from "carbon-components-svelte"; import { Save, @@ -171,7 +171,7 @@ Checkbox, SetTestArr(index, HelpFilled, "secondary", false); }, 1000 * seconds); } - + getConfig(); @@ -180,6 +180,12 @@ Checkbox,

*Arr Settings

+ {#if config.Arrs !== undefined} {#each config.Arrs as arr, i}
- {arr.Name ? arr.Name : i}