Skip to content

Commit 36d27d9

Browse files
Merge pull request datacite#1492 from datacite/reindex-job
Add ReindexByDoiJob to consume DOI reindexing SQS messages sent by the events application
2 parents 2e3cbc0 + 382996b commit 36d27d9

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

app/jobs/reindex_by_doi_job.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
class ReindexByDoiJob < ApplicationJob
4+
queue_as :lupo_background
5+
6+
def perform(doi_id, _options = {})
7+
doi = Doi.find_by(doi: doi_id)
8+
return unless doi.present?
9+
10+
if doi.agency == "datacite"
11+
DataciteDoiImportInBulkJob.perform_later([doi.id], index: DataciteDoi.active_index)
12+
else
13+
OtherDoiImportInBulkJob.perform_later([doi.id], index: OtherDoi.active_index)
14+
end
15+
end
16+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
describe ReindexByDoiJob, type: :job do
6+
let(:datacite_doi) { create(:doi, agency: "datacite") }
7+
let(:other_doi) { create(:doi, agency: "crossref") }
8+
subject(:job) { ReindexByDoiJob.perform_later(datacite_doi.doi) }
9+
10+
it "queues the job" do
11+
expect { job }.to have_enqueued_job(ReindexByDoiJob).on_queue(
12+
"test_lupo_background",
13+
)
14+
end
15+
16+
it "queues DataciteDoiImportInBulkJob for agency 'datacite'" do
17+
ReindexByDoiJob.perform_now(datacite_doi.doi)
18+
19+
enqueued_job = enqueued_jobs.find { |j| j[:job] == DataciteDoiImportInBulkJob }
20+
expect(enqueued_job).to be_present
21+
expect(enqueued_job[:args].first).to eq([datacite_doi.id])
22+
end
23+
24+
it "queues OtherDoiImportInBulkJob for agency 'crossref'" do
25+
ReindexByDoiJob.perform_now(other_doi.doi)
26+
27+
enqueued_job = enqueued_jobs.find { |j| j[:job] == OtherDoiImportInBulkJob }
28+
expect(enqueued_job).to be_present
29+
expect(enqueued_job[:args].first).to eq([other_doi.id])
30+
end
31+
32+
after do
33+
clear_enqueued_jobs
34+
clear_performed_jobs
35+
end
36+
end

0 commit comments

Comments
 (0)