Skip to content
Open
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
1 change: 1 addition & 0 deletions app/jobs/index_job_doi_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class IndexJobDoiRegistration < ApplicationJob
def perform(obj)
EnrichedDoiIndexJob.new.perform(obj.doi)

obj.reload
response = obj.__elasticsearch__.index_document
Rails.logger.error "[Elasticsearch] Error #{response.inspect}" unless %w(created updated).include?(response["result"])
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module Indexable
elsif not %w[Prefix ProviderPrefix ClientPrefix DataciteDoi].include?(self.class.name)
IndexJob.perform_later(self)
elsif instance_of?(DataciteDoi)
# update url before enqueueing so the index job does not race with after_commit :update_url.
update_url
IndexJobDoiRegistration.perform_later(self)

if index_sync_enabled?
Expand Down
2 changes: 2 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2129,7 +2129,9 @@ def validatable?
# providers europ, and DOI registration agencies do their own handle registration, so fetch url from handle system instead
def update_url
return nil if current_user.nil? || !is_registered_or_findable?
return if @updating_url

@updating_url = true
if %w(europ).include?(provider_id) || type == "OtherDoi"
UrlJob.perform_later(doi)
# TODO better define conditions for updating handle system
Expand Down
22 changes: 22 additions & 0 deletions spec/concerns/indexable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,28 @@
end
event.doi_for_source.touch
end

it "sets minted before enqueueing IndexJobDoiRegistration" do
token = User.generate_token(role_id: "client_admin")
unsaved = build(
:doi,
agency: "datacite",
aasm_state: "findable",
minted: nil,
current_user: User.new(token),
)
expect(unsaved.minted).to be_nil

allow(unsaved).to receive(:register_url) do
unsaved.update!(minted: Time.zone.now)
end

expect(IndexJobDoiRegistration).to receive(:perform_later).at_least(:once) do |arg|
expect(DataciteDoi.find(arg.id).minted).to be_present
end

unsaved.save!
end
end
end

Expand Down
33 changes: 33 additions & 0 deletions spec/jobs/index_job_doi_registration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require "rails_helper"

describe IndexJobDoiRegistration, type: :job do
let(:doi) { create(:doi, minted: nil) }

after do
clear_enqueued_jobs
clear_performed_jobs
end

it "queues the job" do
doi
expect { IndexJobDoiRegistration.perform_later(doi) }.
to have_enqueued_job(IndexJobDoiRegistration).on_queue("test_lupo_doi_registration")
end

it "reloads the DOI before indexing so registered is present" do
minted_at = Time.zone.parse("2026-03-29T21:48:59Z")
doi.update_columns(minted: minted_at)
doi.minted = nil

elasticsearch = instance_double("ElasticsearchIndexer")
allow(doi).to receive(:__elasticsearch__).and_return(elasticsearch)
expect(elasticsearch).to receive(:index_document) do
expect(doi.minted).to be_present
{ "result" => "updated" }
end

IndexJobDoiRegistration.perform_now(doi)
end
end