diff --git a/app/jobs/reindex_by_doi_job.rb b/app/jobs/reindex_by_doi_job.rb index 5f1a86e42..f7dc4399a 100644 --- a/app/jobs/reindex_by_doi_job.rb +++ b/app/jobs/reindex_by_doi_job.rb @@ -1,9 +1,18 @@ # frozen_string_literal: true class ReindexByDoiJob < ApplicationJob + include Shoryuken::Worker + queue_as :lupo_background + shoryuken_options queue: -> { "#{ENV["RAILS_ENV"]}_lupo_background" }, auto_delete: true + + def perform(sqs_message = nil, data = nil) + parsed = JSON.parse(data) + return unless parsed.is_a?(Hash) + + doi_id = parsed["doi"] + return if doi_id.blank? - def perform(doi_id, _options = {}) doi = Doi.find_by(doi: doi_id) return unless doi.present? diff --git a/spec/jobs/reindex_by_doi_job_spec.rb b/spec/jobs/reindex_by_doi_job_spec.rb index 271f99603..a5f2ca7bd 100644 --- a/spec/jobs/reindex_by_doi_job_spec.rb +++ b/spec/jobs/reindex_by_doi_job_spec.rb @@ -5,7 +5,7 @@ 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) } + subject(:job) { ReindexByDoiJob.perform_later(nil, { doi: datacite_doi.doi }.to_json) } it "queues the job" do expect { job }.to have_enqueued_job(ReindexByDoiJob).on_queue( @@ -14,7 +14,7 @@ end it "queues DataciteDoiImportInBulkJob for agency 'datacite'" do - ReindexByDoiJob.perform_now(datacite_doi.doi) + ReindexByDoiJob.new.perform(nil, { doi: datacite_doi.doi }.to_json) enqueued_job = enqueued_jobs.find { |j| j[:job] == DataciteDoiImportInBulkJob } expect(enqueued_job).to be_present @@ -22,7 +22,7 @@ end it "queues OtherDoiImportInBulkJob for agency 'crossref'" do - ReindexByDoiJob.perform_now(other_doi.doi) + ReindexByDoiJob.new.perform(nil, { doi: other_doi.doi }.to_json) enqueued_job = enqueued_jobs.find { |j| j[:job] == OtherDoiImportInBulkJob } expect(enqueued_job).to be_present