Skip to content

Commit

Permalink
Merge pull request #1262 from datacite/move_doi_import_sep_queue
Browse files Browse the repository at this point in the history
Move index jobs for dois to their own queue.
  • Loading branch information
richardhallett authored Oct 16, 2024
2 parents a5759f3 + d87e848 commit 197cf0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions app/jobs/index_job_doi_registration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class IndexJobDoiRegistration < ApplicationJob
queue_as :lupo_doi_registration

rescue_from ActiveJob::DeserializationError,
SocketError,
Elasticsearch::Transport::Transport::Errors::BadRequest,
Elasticsearch::Transport::Transport::Error do |error|
Rails.logger.error error.message
end

def perform(obj)
response = obj.__elasticsearch__.index_document
Rails.logger.error "[Elasticsearch] Error #{response.inspect}" unless %w(created updated).include?(response["result"])
end
end
4 changes: 3 additions & 1 deletion app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ module Indexable
included do
after_commit on: %i[create update] do
# use index_document instead of update_document to also update virtual attributes
unless %w[Prefix ProviderPrefix ClientPrefix].include?(self.class.name)
if not %w[Prefix ProviderPrefix ClientPrefix Doi].include?(self.class.name)
IndexJob.perform_later(self)
elsif instance_of?(Doi)
IndexJobDoiRegistration.perform_later(self)
else
__elasticsearch__.index_document
# This is due to the order of indexing, we want to always ensure
Expand Down

0 comments on commit 197cf0e

Please sign in to comment.