mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-14 00:55:10 +00:00
chore: make companion pool a class and store their companion instance
This commit is contained in:
@@ -46,8 +46,9 @@ struct YoutubeConnectionPool
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
struct CompanionConnectionPool
|
class CompanionConnectionPool
|
||||||
property pool : DB::Pool(HTTP::Client)
|
property pool : DB::Pool(HTTP::Client)
|
||||||
|
property companion : URI
|
||||||
|
|
||||||
def initialize(companion, capacity = 5, timeout = 5.0)
|
def initialize(companion, capacity = 5, timeout = 5.0)
|
||||||
options = DB::Pool::Options.new(
|
options = DB::Pool::Options.new(
|
||||||
@@ -57,8 +58,10 @@ struct CompanionConnectionPool
|
|||||||
checkout_timeout: timeout
|
checkout_timeout: timeout
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@companion = companion.private_url
|
||||||
|
|
||||||
@pool = DB::Pool(HTTP::Client).new(options) do
|
@pool = DB::Pool(HTTP::Client).new(options) do
|
||||||
next make_client(companion.private_url, use_http_proxy: false)
|
next make_client(@companion, use_http_proxy: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -70,10 +73,7 @@ struct CompanionConnectionPool
|
|||||||
rescue ex
|
rescue ex
|
||||||
conn.close
|
conn.close
|
||||||
|
|
||||||
scheme = "https" if conn.tls || "http"
|
conn = make_client(@companion, use_http_proxy: false)
|
||||||
same_companion = "#{scheme}://#{conn.host}:#{conn.port}"
|
|
||||||
|
|
||||||
conn = make_client(URI.parse(same_companion), use_http_proxy: false)
|
|
||||||
|
|
||||||
response = yield conn
|
response = yield conn
|
||||||
ensure
|
ensure
|
||||||
|
|||||||
Reference in New Issue
Block a user