summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-01-19 18:51:57 +0000
committerOmar Roth <omarroth@hotmail.com>2018-01-19 18:51:57 +0000
commitf77dcb7f9ba9fbb0cb51ccdd34cfbab5a85de5e3 (patch)
tree54c320480b09aec5c7eb48ba0a6c8b0d31bdb45a
parent61e3b4721050dab835156345ff597e1142113142 (diff)
downloadinvidious-f77dcb7f9ba9fbb0cb51ccdd34cfbab5a85de5e3.tar.gz
invidious-f77dcb7f9ba9fbb0cb51ccdd34cfbab5a85de5e3.tar.bz2
invidious-f77dcb7f9ba9fbb0cb51ccdd34cfbab5a85de5e3.zip
Randomly refresh HTTP clients
-rw-r--r--src/invidious.cr7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index a0a6a4f7..8ba75cc2 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -21,9 +21,12 @@ end
# Refresh all the connections in the pool by crawling recommended
spawn do
# Arbitrary start value
- id = Deque.new(50,"0xjKNDMgE54")
+ id = Deque.new(50, "0xjKNDMgE54")
while true
client = get_client
+ if rand(30) > 1
+ client = HTTP::Client.new(URL, CONTEXT)
+ end
time = Time.now
begin
@@ -33,7 +36,7 @@ spawn do
rvs << HTTP::Params.parse(rv).to_h
end
rvs.each do |rv|
- id << rv["id"]
+ id << rv["id"]
end
puts "#{Time.now} 200 GET #{elapsed_text(Time.now - time)}"
rescue ex