Skip to content

Commit f8293b1

Browse files
authored
Merge pull request #762 from alphagov/answer-analysis-job
Add AnswerAnalysisJob to kick off separate analysis jobs
2 parents 1fd6beb + 37a7475 commit f8293b1

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

app/jobs/answer_analysis_job.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AnswerAnalysisJob < ApplicationJob
2+
def perform(answer_id)
3+
AnswerAnalysis::TagTopicsJob.perform_later(answer_id)
4+
AnswerAnalysis::AnswerRelevancyJob.perform_later(answer_id)
5+
end
6+
end

app/jobs/compose_answer_job.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ def perform(question_id)
1515
end
1616

1717
if answer.persisted?
18-
# TODO: Once we've added a few metrics we should move these to a single job that
19-
# kicks off all analysis jobs.
20-
AnswerAnalysis::TagTopicsJob.perform_later(answer.id)
21-
AnswerAnalysis::AnswerRelevancyJob.perform_later(answer.id)
18+
AnswerAnalysisJob.perform_later(answer.id)
19+
2220
end
2321
end
2422
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
RSpec.describe AnswerAnalysisJob do
2+
let(:answer) { build :answer }
3+
4+
before do
5+
allow(AnswerAnalysis::TagTopicsJob).to receive(:perform_later)
6+
allow(AnswerAnalysis::AnswerRelevancyJob).to receive(:perform_later)
7+
end
8+
9+
it "calls the AnswerAnalysis::TagTopicsJob with the answer id" do
10+
described_class.new.perform(answer.id)
11+
expect(AnswerAnalysis::TagTopicsJob).to have_received(:perform_later).with(answer.id)
12+
end
13+
14+
it "calls the AnswerAnalysis::AnswerRelevancyJob with the answer id" do
15+
described_class.new.perform(answer.id)
16+
expect(AnswerAnalysis::AnswerRelevancyJob).to have_received(:perform_later).with(answer.id)
17+
end
18+
end

spec/jobs/compose_answer_job_spec.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
before do
77
allow(AnswerComposition::Composer).to receive(:call).and_return(returned_answer)
8-
allow(AnswerAnalysis::TagTopicsJob).to receive(:perform_later)
9-
allow(AnswerAnalysis::AnswerRelevancyJob).to receive(:perform_later)
8+
allow(AnswerAnalysisJob).to receive(:perform_later)
109
end
1110

1211
it_behaves_like "a job in queue", "answer"
@@ -18,14 +17,9 @@
1817
.and change(AnswerSource, :count).by(2)
1918
end
2019

21-
it "calls the AnswerAnalysis::TagTopicsJob with the answer_id" do
20+
it "calls the AnswerAnalysisJob with the answer id" do
2221
described_class.new.perform(question.id)
23-
expect(AnswerAnalysis::TagTopicsJob).to have_received(:perform_later).with(returned_answer.id)
24-
end
25-
26-
it "calls the AnswerAnalysis::AnswerRelevancyJob with the answer_id" do
27-
described_class.new.perform(question.id)
28-
expect(AnswerAnalysis::AnswerRelevancyJob).to have_received(:perform_later).with(returned_answer.id)
22+
expect(AnswerAnalysisJob).to have_received(:perform_later).with(returned_answer.id)
2923
end
3024

3125
context "when the question has already been answered" do

0 commit comments

Comments
 (0)