@@ -46,8 +46,22 @@ struct YoutubeConnectionPool
4646 end
4747end
4848
49+ class CompanionWrapper
50+ property client : HTTP ::Client
51+ property companion : Config ::CompanionConfig
52+
53+ def initialize (companion : Config ::CompanionConfig )
54+ @companion = companion
55+ @client = HTTP ::Client .new(companion.private_url)
56+ end
57+
58+ def close
59+ @client .close
60+ end
61+ end
62+
4963struct CompanionConnectionPool
50- property pool : DB ::Pool (HTTP :: Client )
64+ property pool : DB ::Pool (CompanionWrapper )
5165
5266 def initialize (capacity = 5 , timeout = 5.0 )
5367 options = DB ::Pool ::Options .new(
@@ -57,26 +71,28 @@ struct CompanionConnectionPool
5771 checkout_timeout: timeout
5872 )
5973
60- @pool = DB ::Pool (HTTP :: Client ).new(options) do
74+ @pool = DB ::Pool (CompanionWrapper ).new(options) do
6175 companion = CONFIG .invidious_companion.sample
62- next make_client(companion.private_url, use_http_proxy: false )
76+ client = make_client(companion.private_url, use_http_proxy: false )
77+ CompanionWrapper .new(companion: companion)
6378 end
6479 end
6580
6681 def client (& )
67- conn = pool.checkout
82+ wrapper = pool.checkout
6883
6984 begin
70- response = yield conn
85+ response = yield wrapper
7186 rescue ex
72- conn .close
87+ wrapper.client .close
7388
7489 companion = CONFIG .invidious_companion.sample
75- conn = make_client(companion.private_url, use_http_proxy: false )
90+ client = make_client(companion.private_url, use_http_proxy: false )
91+ wrapper = CompanionWrapper .new(companion: companion)
7692
77- response = yield conn
93+ response = yield wrapper
7894 ensure
79- pool.release(conn )
95+ pool.release(wrapper )
8096 end
8197
8298 response
0 commit comments