From 7f38e0535f9ac6535bd3f475a3bfcfc1d43ecd14 Mon Sep 17 00:00:00 2001 From: Ben Adrian Sarmiento Date: Fri, 12 Jul 2024 14:22:49 +0200 Subject: [PATCH] Adjust config names to per minute --- internal/app.go | 4 ++-- internal/config/types.go | 22 +++++++++++----------- pkg/http/rate_limiter.go | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/app.go b/internal/app.go index 4a6b94a..c30d994 100644 --- a/internal/app.go +++ b/internal/app.go @@ -81,7 +81,7 @@ func MainApp(configPath string) { } } - rateLimiter := http.NewRateLimiter(config.GetAPIRateLimitPerSecond()) + rateLimiter := http.NewRateLimiter(config.GetAPIRateLimitPerMinute()) apiClient := http.NewHTTPClient( config.GetToken(), @@ -127,7 +127,7 @@ func MainApp(configPath string) { } defer workerPool.Release() - torrentsRateLimiter := http.NewRateLimiter(config.GetTorrentsRateLimitPerSecond()) + torrentsRateLimiter := http.NewRateLimiter(config.GetTorrentsRateLimitPerMinute()) rd := realdebrid.NewRealDebrid( apiClient, diff --git a/internal/config/types.go b/internal/config/types.go index 29d4f13..6d51ba3 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -10,7 +10,7 @@ type ConfigInterface interface { EnableRepair() bool EnableRetainFolderNameExtension() bool EnableRetainRDTorrentName() bool - GetAPIRateLimitPerSecond() int + GetAPIRateLimitPerMinute() int GetApiTimeoutSecs() int GetConfig() ZurgConfig GetDirectories() []string @@ -31,7 +31,7 @@ type ConfigInterface interface { GetRepairEveryMins() int GetRetriesUntilFailed() int GetToken() string - GetTorrentsRateLimitPerSecond() int + GetTorrentsRateLimitPerMinute() int GetUsername() string GetVersion() string MeetsConditions(directory, torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64, mediaInfos []*ffprobe.ProbeData) bool @@ -48,7 +48,7 @@ type ZurgConfig struct { Version string `yaml:"zurg" json:"-"` Token string `yaml:"token" json:"-"` - APIRateLimitPerSecond int `yaml:"api_rate_limit_per_second" json:"api_rate_limit_per_second"` + APIRateLimitPerMinute int `yaml:"api_rate_limit_per_second" json:"api_rate_limit_per_second"` ApiTimeoutSecs int `yaml:"api_timeout_secs" json:"api_timeout_secs"` AutoAnalyzeNewTorrents bool `yaml:"auto_analyze_new_torrents" json:"auto_analyze_new_torrents"` CacheNetworkTestResults bool `yaml:"cache_network_test_results" json:"cache_network_test_results"` @@ -76,7 +76,7 @@ type ZurgConfig struct { RetainRDTorrentName bool `yaml:"retain_rd_torrent_name" json:"retain_rd_torrent_name"` RetriesUntilFailed int `yaml:"retries_until_failed" json:"retries_until_failed"` ServeFromRclone bool `yaml:"serve_from_rclone" json:"serve_from_rclone"` - TorrentsRateLimitPerSecond int `yaml:"torrents_rate_limit_per_second" json:"torrents_rate_limit_per_second"` + TorrentsRateLimitPerMinute int `yaml:"torrents_rate_limit_per_second" json:"torrents_rate_limit_per_second"` Username string `yaml:"username" json:"username"` } @@ -243,16 +243,16 @@ func (z *ZurgConfig) ShouldHideBrokenTorrents() bool { return z.HideBrokenTorrents } -func (z *ZurgConfig) GetAPIRateLimitPerSecond() int { - if z.APIRateLimitPerSecond == 0 { +func (z *ZurgConfig) GetAPIRateLimitPerMinute() int { + if z.APIRateLimitPerMinute == 0 { return 250 } - return z.APIRateLimitPerSecond + return z.APIRateLimitPerMinute } -func (z *ZurgConfig) GetTorrentsRateLimitPerSecond() int { - if z.TorrentsRateLimitPerSecond == 0 { - return 1 +func (z *ZurgConfig) GetTorrentsRateLimitPerMinute() int { + if z.TorrentsRateLimitPerMinute == 0 { + return 60 } - return z.TorrentsRateLimitPerSecond + return z.TorrentsRateLimitPerMinute } diff --git a/pkg/http/rate_limiter.go b/pkg/http/rate_limiter.go index 1389187..1149233 100644 --- a/pkg/http/rate_limiter.go +++ b/pkg/http/rate_limiter.go @@ -6,9 +6,9 @@ type RateLimiter struct { ticker *time.Ticker } -func NewRateLimiter(apiRateLimitPerSecond int) *RateLimiter { +func NewRateLimiter(rateLimitPerMinute int) *RateLimiter { return &RateLimiter{ - ticker: time.NewTicker(time.Second / time.Duration(apiRateLimitPerSecond)), + ticker: time.NewTicker(time.Minute / time.Duration(rateLimitPerMinute)), } }