A platform for community discussion. Free, open, simple.
FIX: Skip topic localization backfill when hourly rate 0 (#38489)
Natalie Tay0b608fcef80d
diff --git a/plugins/discourse-ai/app/jobs/scheduled/topic_localization_backfill.rb b/plugins/discourse-ai/app/jobs/scheduled/topic_localization_backfill.rbindex 7b1501837a2..11a04cdb487 100644--- a/plugins/discourse-ai/app/jobs/scheduled/topic_localization_backfill.rb+++ b/plugins/discourse-ai/app/jobs/scheduled/topic_localization_backfill.rb@@ -21,6 +21,8 @@ module Jobsendlimit = SiteSetting.ai_translation_backfill_hourly_rate / (60 / 5) # this job runs in 5-minute intervals+ return if limit == 0+Jobs.enqueue(:localize_topics, limit:)enddiff --git a/plugins/discourse-ai/spec/jobs/scheduled/topic_localization_backfill_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/topic_localization_backfill_spec.rbnew file mode 100644index 00000000000..42ca7d2cea8--- /dev/null+++ b/plugins/discourse-ai/spec/jobs/scheduled/topic_localization_backfill_spec.rb@@ -0,0 +1,43 @@+# frozen_string_literal: true++describe Jobs::TopicLocalizationBackfill do+ before do+ enable_current_plugin+ assign_fake_provider_to(:ai_default_llm_model)+ SiteSetting.ai_translation_backfill_hourly_rate = 100+ SiteSetting.content_localization_supported_locales = "en"+ SiteSetting.ai_translation_enabled = true+ end++ it "does not enqueue topic translation when translator disabled" do+ SiteSetting.discourse_ai_enabled = false++ expect_not_enqueued_with(job: :localize_topics) { described_class.new.execute({}) }+ end++ it "does not enqueue topic translation when ai_translation_enabled disabled" do+ SiteSetting.ai_translation_enabled = false++ expect_not_enqueued_with(job: :localize_topics) { described_class.new.execute({}) }+ end++ it "does not enqueue topic translation if backfill languages are not set" do+ SiteSetting.content_localization_supported_locales = ""++ expect_not_enqueued_with(job: :localize_topics) { described_class.new.execute({}) }+ end++ it "does not enqueue topic translation if backfill limit is set to 0" do+ SiteSetting.ai_translation_backfill_hourly_rate = 0++ expect_not_enqueued_with(job: :localize_topics) { described_class.new.execute({}) }+ end++ it "enqueues topic translation with correct limit" do+ SiteSetting.ai_translation_backfill_hourly_rate = 100++ described_class.new.execute({})++ expect_job_enqueued(job: :localize_topics, args: { limit: 8 })+ end+end