Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/jobs/regular/detect_translate_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def execute(args)

begin
DiscourseTranslator::PostTranslator.translate(post, locale)
rescue FinalDestination::SSRFDetector::LookupFailedError
# do nothing, there are too many sporadic lookup failures
Comment on lines +23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to consider queuing the job again instead with some delay? I'm curious what happens if we do nothing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need to. This job itself is not critical as the backfill scheduled job will cover any failures. The backfill does most recent posts first.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification!

rescue => e
Rails.logger.error(
"Discourse Translator: Failed to translate post #{post.id} to #{locale}: #{e.message}",
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/regular/detect_translate_topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def execute(args)

begin
DiscourseTranslator::TopicTranslator.translate(topic, locale)
rescue FinalDestination::SSRFDetector::LookupFailedError
# do nothing, there are too many sporadic lookup failures
rescue => e
Rails.logger.error(
"Discourse Translator: Failed to translate topic #{topic.id} to #{locale}: #{e.message}",
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/regular/translate_categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def execute(args)
next if CategoryLocalization.exists?(category_id: category.id, locale: locale)
begin
DiscourseTranslator::CategoryTranslator.translate(category, locale)
rescue FinalDestination::SSRFDetector::LookupFailedError
# do nothing, there are too many sporadic lookup failures
rescue => e
Rails.logger.error(
"Discourse Translator: Failed to translate category #{category.id} to #{locale}: #{e.message}",
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/regular/translate_posts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def execute(args)
posts.each do |post|
begin
DiscourseTranslator::PostTranslator.translate(post, locale)
rescue FinalDestination::SSRFDetector::LookupFailedError
# do nothing, there are too many sporadic lookup failures
rescue => e
Rails.logger.error(
"Discourse Translator: Failed to translate post #{post.id} to #{locale}: #{e.message}",
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/regular/translate_topics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def execute(args)
topics.each do |topic|
begin
DiscourseTranslator::TopicTranslator.translate(topic, locale)
rescue FinalDestination::SSRFDetector::LookupFailedError
# do nothing, there are too many sporadic lookup failures
rescue => e
Rails.logger.error(
"Discourse Translator: Failed to translate topic #{topic.id} to #{locale}: #{e.message}",
Expand Down
2 changes: 1 addition & 1 deletion app/services/discourse_translator/post_locale_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.detect_locale(post)
translator = DiscourseTranslator::Provider::TranslatorProvider.get
detected_locale = translator.detect!(post)
locale = LocaleNormalizer.normalize_to_i18n(detected_locale)
post.update!(locale:)
post.update_column(:locale, locale)
locale
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/services/post_locale_detector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@
"zh_CN",
)
end

it "bypasses validations when updating locale" do
post.update_column(:raw, "A")

translator.stubs(:detect!).with(post).returns("zh_CN")

described_class.detect_locale(post)
expect(post.reload.locale).to eq("zh_CN")
end
end
end
Loading