Move decrypt function updating into job class

This commit is contained in:
Matthew McGarvey 2020-10-16 20:49:31 -05:00
parent cfef390c9d
commit ddc8892624
3 changed files with 21 additions and 22 deletions

View File

@ -168,19 +168,14 @@ if config.statistics_enabled
end
Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)
Invidious::Jobs.register Invidious::Jobs::UpdateDecryptFunctionJob.new
Invidious::Jobs.start_all
def popular_videos
Invidious::Jobs::PullPopularVideosJob::POPULAR_VIDEOS.get
end
DECRYPT_FUNCTION = [] of {SigProc, Int32}
spawn do
update_decrypt_function do |function|
DECRYPT_FUNCTION.clear
function.each { |i| DECRYPT_FUNCTION << i }
end
end
DECRYPT_FUNCTION = Invidious::Jobs::UpdateDecryptFunctionJob::DECRYPT_FUNCTION
if CONFIG.captcha_key
spawn do

View File

@ -65,21 +65,6 @@ def pull_popular_videos(db)
end
end
def update_decrypt_function
loop do
begin
decrypt_function = fetch_decrypt_function
yield decrypt_function
rescue ex
# TODO: Log error
next
ensure
sleep 1.minute
Fiber.yield
end
end
end
def bypass_captcha(captcha_key, logger)
loop do
begin

View File

@ -0,0 +1,19 @@
class Invidious::Jobs::UpdateDecryptFunctionJob < Invidious::Jobs::BaseJob
DECRYPT_FUNCTION = [] of {SigProc, Int32}
def begin
loop do
begin
decrypt_function = fetch_decrypt_function
DECRYPT_FUNCTION.clear
decrypt_function.each { |df| DECRYPT_FUNCTION << df }
rescue ex
# TODO: Log error
next
ensure
sleep 1.minute
Fiber.yield
end
end
end
end