Add rate limiter
This commit is contained in:
@@ -57,8 +57,10 @@ func MainApp(configPath string) {
|
||||
proxyURL = os.Getenv("PROXY")
|
||||
}
|
||||
|
||||
repoClient4 := http.NewHTTPClient("", 0, 1, false, []string{}, proxyURL, log.Named("network_test"))
|
||||
repoClient6 := http.NewHTTPClient("", 0, 1, true, []string{}, proxyURL, log.Named("network_test"))
|
||||
dummyLimiter := http.NewRateLimiter(1000)
|
||||
|
||||
repoClient4 := http.NewHTTPClient("", 0, 1, false, []string{}, proxyURL, dummyLimiter, log.Named("network_test"))
|
||||
repoClient6 := http.NewHTTPClient("", 0, 1, true, []string{}, proxyURL, dummyLimiter, log.Named("network_test"))
|
||||
repo := http.NewIPRepository(repoClient4, repoClient6, "", log.Named("network_test"))
|
||||
|
||||
var hosts []string
|
||||
@@ -79,6 +81,8 @@ func MainApp(configPath string) {
|
||||
}
|
||||
}
|
||||
|
||||
rateLimiter := http.NewRateLimiter(config.GetAPIRateLimitPerSecond())
|
||||
|
||||
apiClient := http.NewHTTPClient(
|
||||
config.GetToken(),
|
||||
config.GetRetriesUntilFailed(), // default retries = 2
|
||||
@@ -86,6 +90,7 @@ func MainApp(configPath string) {
|
||||
false, // no need for ipv6 support
|
||||
[]string{}, // no optimal hosts needed
|
||||
proxyURL,
|
||||
rateLimiter,
|
||||
log.Named("api_client"),
|
||||
)
|
||||
|
||||
@@ -96,6 +101,7 @@ func MainApp(configPath string) {
|
||||
false, // no need for ipv6 support
|
||||
[]string{}, // no optimal hosts needed
|
||||
proxyURL,
|
||||
rateLimiter,
|
||||
log.Named("unrestrict_client"),
|
||||
)
|
||||
|
||||
@@ -106,6 +112,7 @@ func MainApp(configPath string) {
|
||||
config.ShouldForceIPv6(),
|
||||
hosts,
|
||||
proxyURL,
|
||||
rateLimiter,
|
||||
log.Named("download_client"),
|
||||
)
|
||||
|
||||
@@ -120,11 +127,14 @@ func MainApp(configPath string) {
|
||||
}
|
||||
defer workerPool.Release()
|
||||
|
||||
torrentsRateLimiter := http.NewRateLimiter(config.GetTorrentsRateLimitPerSecond())
|
||||
|
||||
rd := realdebrid.NewRealDebrid(
|
||||
apiClient,
|
||||
unrestrictClient,
|
||||
downloadClient,
|
||||
workerPool,
|
||||
torrentsRateLimiter,
|
||||
config,
|
||||
log.Named("realdebrid"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user