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
16 changes: 16 additions & 0 deletions app/jobs/reindex_by_doi_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class ReindexByDoiJob < ApplicationJob
queue_as :lupo_background

def perform(doi_id, _options = {})
doi = Doi.find_by(doi: doi_id)
return unless doi.present?

if doi.agency == "datacite"
DataciteDoiImportInBulkJob.perform_later([doi.id], index: DataciteDoi.active_index)
else
OtherDoiImportInBulkJob.perform_later([doi.id], index: OtherDoi.active_index)
end
end
end
36 changes: 36 additions & 0 deletions spec/jobs/reindex_by_doi_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require "rails_helper"

describe ReindexByDoiJob, type: :job do
let(:datacite_doi) { create(:doi, agency: "datacite") }
let(:other_doi) { create(:doi, agency: "crossref") }
subject(:job) { ReindexByDoiJob.perform_later(datacite_doi.doi) }

it "queues the job" do
expect { job }.to have_enqueued_job(ReindexByDoiJob).on_queue(
"test_lupo_background",
)
end

it "queues DataciteDoiImportInBulkJob for agency 'datacite'" do
ReindexByDoiJob.perform_now(datacite_doi.doi)

enqueued_job = enqueued_jobs.find { |j| j[:job] == DataciteDoiImportInBulkJob }
expect(enqueued_job).to be_present
expect(enqueued_job[:args].first).to eq([datacite_doi.id])
end

it "queues OtherDoiImportInBulkJob for agency 'crossref'" do
ReindexByDoiJob.perform_now(other_doi.doi)

enqueued_job = enqueued_jobs.find { |j| j[:job] == OtherDoiImportInBulkJob }
expect(enqueued_job).to be_present
expect(enqueued_job[:args].first).to eq([other_doi.id])
end

after do
clear_enqueued_jobs
clear_performed_jobs
end
end