File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33module Jobs
4- class DetectPostsLocale < ::Jobs ::Base
4+ class PostsLocaleDetectionBackfill < ::Jobs ::Scheduled
5+ every 5 . minutes
56 cluster_concurrency 1
6- sidekiq_options retry : false
7-
8- BATCH_SIZE = 50
97
108 def execute ( args )
119 return unless SiteSetting . translator_enabled
1210 return unless SiteSetting . experimental_content_translation
11+ return if SiteSetting . automatic_translation_backfill_rate == 0
1312
13+ limit = SiteSetting . automatic_translation_backfill_rate
1414 posts =
1515 Post
1616 . where ( locale : nil )
1717 . where ( deleted_at : nil )
1818 . where ( "posts.user_id > 0" )
1919 . where . not ( raw : [ nil , "" ] )
2020 . order ( updated_at : :desc )
21- . limit ( BATCH_SIZE )
21+ . limit ( limit )
2222 return if posts . empty?
2323
2424 posts . each do |post |
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3- describe Jobs ::DetectPostsLocale do
3+ describe Jobs ::PostsLocaleDetectionBackfill do
44 fab! ( :post ) { Fabricate ( :post , locale : nil ) }
55 subject ( :job ) { described_class . new }
66
77 before do
88 SiteSetting . translator_enabled = true
99 SiteSetting . experimental_content_translation = true
10+ SiteSetting . automatic_translation_backfill_rate = 100
1011 end
1112
1213 it "does nothing when translator is disabled" do
4344 post_2 . update! ( updated_at : 2 . day . ago )
4445 post_3 . update! ( updated_at : 4 . day . ago )
4546
46- original_batch = described_class ::BATCH_SIZE
47- described_class . const_set ( :BATCH_SIZE , 1 )
47+ SiteSetting . automatic_translation_backfill_rate = 1
4848
4949 DiscourseTranslator ::PostLocaleDetector . expects ( :detect_locale ) . with ( post_2 ) . once
5050 DiscourseTranslator ::PostLocaleDetector . expects ( :detect_locale ) . with ( post ) . never
5151 DiscourseTranslator ::PostLocaleDetector . expects ( :detect_locale ) . with ( post_3 ) . never
5252
5353 job . execute ( { } )
54- ensure
55- described_class . const_set ( :BATCH_SIZE , original_batch )
5654 end
5755
5856 it "skips bot posts" do
You can’t perform that action at this time.
0 commit comments