fix: Sentiment analysis queue update (#7552)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class Enterprise::SentimentAnalysisJob < ApplicationJob
|
class Enterprise::SentimentAnalysisJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :low
|
||||||
|
|
||||||
def perform(message)
|
def perform(message)
|
||||||
return if message.account.locale != 'en'
|
return if message.account.locale != 'en'
|
||||||
@@ -27,11 +27,11 @@ class Enterprise::SentimentAnalysisJob < ApplicationJob
|
|||||||
|
|
||||||
# Model initializes OnnxRuntime::Model, with given file for inference session and to create the tensor
|
# Model initializes OnnxRuntime::Model, with given file for inference session and to create the tensor
|
||||||
def model
|
def model
|
||||||
model = save_and_open_sentiment_file
|
model_file = save_and_open_sentiment_file
|
||||||
|
|
||||||
return if File.empty?(model)
|
return if File.empty?(model_file)
|
||||||
|
|
||||||
Informers::SentimentAnalysis.new(model)
|
Informers::SentimentAnalysis.new(model_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
def label_val(sentiment)
|
def label_val(sentiment)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Enterprise::Message
|
module Enterprise::Message
|
||||||
def update_message_sentiments
|
def update_message_sentiments
|
||||||
::Enterprise::SentimentAnalysisJob.perform_later(self)
|
::Enterprise::SentimentAnalysisJob.perform_later(self) if ENV.fetch('SENTIMENT_FILE_PATH', nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ RSpec.describe Message do
|
|||||||
let(:message) { build(:message, message_type: :incoming, content_type: nil, account: create(:account)) }
|
let(:message) { build(:message, message_type: :incoming, content_type: nil, account: create(:account)) }
|
||||||
|
|
||||||
it 'calls SentimentAnalysisJob' do
|
it 'calls SentimentAnalysisJob' do
|
||||||
allow(Enterprise::SentimentAnalysisJob).to receive(:perform_later).and_return(:perform_later).with(message)
|
with_modified_env SENTIMENT_FILE_PATH: 'sentiment-analysis.onnx' do
|
||||||
|
allow(Enterprise::SentimentAnalysisJob).to receive(:perform_later).and_return(:perform_later).with(message)
|
||||||
|
|
||||||
message.save!
|
message.save!
|
||||||
|
|
||||||
expect(Enterprise::SentimentAnalysisJob).to have_received(:perform_later)
|
expect(Enterprise::SentimentAnalysisJob).to have_received(:perform_later)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user