From ddc88926243e8646c9c6f31409baa65e25e90d96 Mon Sep 17 00:00:00 2001 From: Matthew McGarvey Date: Fri, 16 Oct 2020 20:49:31 -0500 Subject: [PATCH] Move decrypt function updating into job class --- src/invidious.cr | 9 ++------- src/invidious/helpers/jobs.cr | 15 --------------- .../jobs/update_decrypt_function_job.cr | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 src/invidious/jobs/update_decrypt_function_job.cr diff --git a/src/invidious.cr b/src/invidious.cr index ecdd1476..ddc4736b 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -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 diff --git a/src/invidious/helpers/jobs.cr b/src/invidious/helpers/jobs.cr index 8ce6690e..cc602803 100644 --- a/src/invidious/helpers/jobs.cr +++ b/src/invidious/helpers/jobs.cr @@ -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 diff --git a/src/invidious/jobs/update_decrypt_function_job.cr b/src/invidious/jobs/update_decrypt_function_job.cr new file mode 100644 index 00000000..5332c672 --- /dev/null +++ b/src/invidious/jobs/update_decrypt_function_job.cr @@ -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