diff options
| author | Omar Roth <omarroth@protonmail.com> | 2019-11-01 07:34:36 -0400 |
|---|---|---|
| committer | Omar Roth <omarroth@protonmail.com> | 2019-11-01 07:34:36 -0400 |
| commit | 833a60f29cda7ce38c8d732b44d27bc075e37357 (patch) | |
| tree | a71e09386304b6834cc708219634525b550802c9 | |
| parent | f776d67c03c535633c723e98f15a3f8729ade78c (diff) | |
| download | invidious-833a60f29cda7ce38c8d732b44d27bc075e37357.tar.gz invidious-833a60f29cda7ce38c8d732b44d27bc075e37357.tar.bz2 invidious-833a60f29cda7ce38c8d732b44d27bc075e37357.zip | |
Update pubsub to use client pool
| -rw-r--r-- | src/invidious/helpers/jobs.cr | 5 | ||||
| -rw-r--r-- | src/invidious/helpers/utils.cr | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/invidious/helpers/jobs.cr b/src/invidious/helpers/jobs.cr index b82cb1ac..6bca0dae 100644 --- a/src/invidious/helpers/jobs.cr +++ b/src/invidious/helpers/jobs.cr @@ -127,6 +127,8 @@ def subscribe_to_feeds(db, logger, key, config) end max_channel = Channel(Int32).new + client_pool = HTTPPool.new(PUBSUB_URL, capacity: max_threads, timeout: 0.05) + spawn do max_threads = max_channel.receive active_threads = 0 @@ -147,12 +149,13 @@ def subscribe_to_feeds(db, logger, key, config) spawn do begin - response = subscribe_pubsub(ucid, key, config) + response = subscribe_pubsub(ucid, key, config, client_pool) if response.status_code >= 400 logger.puts("#{ucid} : #{response.body}") end rescue ex + logger.puts("#{ucid} : #{ex.message}") end active_channel.send(true) diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 4bf2031e..d9ada146 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -1949,7 +1949,7 @@ def sha256(text) return digest.hexdigest end -def subscribe_pubsub(topic, key, config) +def subscribe_pubsub(topic, key, config, client_pool) case topic when .match(/^UC[A-Za-z0-9_-]{22}$/) topic = "channel_id=#{topic}" @@ -1961,7 +1961,6 @@ def subscribe_pubsub(topic, key, config) # TODO end - client = make_client(PUBSUB_URL) time = Time.utc.to_unix.to_s nonce = Random::Secure.hex(4) signature = "#{time}:#{nonce}" @@ -1977,7 +1976,7 @@ def subscribe_pubsub(topic, key, config) "hub.secret" => key.to_s, } - return client.post("/subscribe", form: body) + return client_pool.client &.post("/subscribe", form: body) end def parse_range(range) |
