discourse-ai/app/jobs/regular/post_sentiment_analysis.rb

18 lines
467 B
Ruby
Raw Normal View History

2023-02-22 18:46:53 -05:00
# frozen_string_literal: true
module ::Jobs
class PostSentimentAnalysis < ::Jobs::Base
2023-02-22 18:46:53 -05:00
def execute(args)
return unless SiteSetting.ai_sentiment_enabled
return if (post_id = args[:post_id]).blank?
2023-02-22 18:46:53 -05:00
post = Post.find_by(id: post_id, post_type: Post.types[:regular])
return if post&.raw.blank?
DiscourseAi::PostClassificator.new(
DiscourseAi::Sentiment::SentimentClassification.new,
).classify!(post)
2023-02-22 18:46:53 -05:00
end
end
end