diff --git a/app/jobs/regular/detect_posts_locale.rb b/app/jobs/scheduled/posts_locale_detection_backfill.rb similarity index 78% rename from app/jobs/regular/detect_posts_locale.rb rename to app/jobs/scheduled/posts_locale_detection_backfill.rb index 835d13a8..2f665791 100644 --- a/app/jobs/regular/detect_posts_locale.rb +++ b/app/jobs/scheduled/posts_locale_detection_backfill.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true module Jobs - class DetectPostsLocale < ::Jobs::Base + class PostsLocaleDetectionBackfill < ::Jobs::Scheduled + every 5.minutes cluster_concurrency 1 - sidekiq_options retry: false - - BATCH_SIZE = 50 def execute(args) return unless SiteSetting.translator_enabled return unless SiteSetting.experimental_content_translation + return if SiteSetting.automatic_translation_backfill_rate == 0 + limit = SiteSetting.automatic_translation_backfill_rate posts = Post .where(locale: nil) @@ -18,7 +18,7 @@ def execute(args) .where("posts.user_id > 0") .where.not(raw: [nil, ""]) .order(updated_at: :desc) - .limit(BATCH_SIZE) + .limit(limit) return if posts.empty? posts.each do |post| diff --git a/spec/jobs/detect_posts_locale_spec.rb b/spec/jobs/posts_locale_detection_backfill_spec.rb similarity index 91% rename from spec/jobs/detect_posts_locale_spec.rb rename to spec/jobs/posts_locale_detection_backfill_spec.rb index 056cb2fd..227f88a8 100644 --- a/spec/jobs/detect_posts_locale_spec.rb +++ b/spec/jobs/posts_locale_detection_backfill_spec.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true -describe Jobs::DetectPostsLocale do +describe Jobs::PostsLocaleDetectionBackfill do fab!(:post) { Fabricate(:post, locale: nil) } subject(:job) { described_class.new } before do SiteSetting.translator_enabled = true SiteSetting.experimental_content_translation = true + SiteSetting.automatic_translation_backfill_rate = 100 end it "does nothing when translator is disabled" do @@ -43,16 +44,13 @@ post_2.update!(updated_at: 2.day.ago) post_3.update!(updated_at: 4.day.ago) - original_batch = described_class::BATCH_SIZE - described_class.const_set(:BATCH_SIZE, 1) + SiteSetting.automatic_translation_backfill_rate = 1 DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(post_2).once DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(post).never DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(post_3).never job.execute({}) - ensure - described_class.const_set(:BATCH_SIZE, original_batch) end it "skips bot posts" do