Skip to content

Commit

Permalink
background job of reindexing. datacite/datacite#965
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 19, 2020
1 parent 7034e81 commit 30b600d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
9 changes: 9 additions & 0 deletions app/jobs/doi_not_indexed_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class DoiNotIndexedJob < ApplicationJob
queue_as :lupo_background

def perform(client_id, _options = {})
Doi.import_by_client(client_id: client_id)
end
end
13 changes: 2 additions & 11 deletions app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -718,17 +718,8 @@ def self.import_dois_not_indexed(query: nil)

# loop through repositories that have DOIs not indexed in Elasticsearch
table.each do |row|
client = ::Client.where(deleted_at: nil).where(symbol: row["Repository ID"]).first
if client.nil?
puts "Client not found for client ID #{row["Repository ID"]}."
exit
end

# import DOIs for client. Ignore repositories with more than 10K DOIs
if client.dois.length <= 10000
puts "#{client.dois.length} DOIs for repository #{client.symbol} will be imported."
Doi.import_by_client(client_id: client.symbol, total_count: client.dois.length)
end
Rails.logger.info "Indexing missing DOIs for repository #{row["Repository ID"]}."
DoiNotIndexedJob.perform_later(row["Repository ID"])
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ def self.import_one(doi_id: nil)
message
end

def self.import_by_client(client_id: nil, total_count: nil)
def self.import_by_client(client_id: nil)
client = ::Client.where(symbol: client_id).first
return nil if client.blank?

Expand Down Expand Up @@ -1271,7 +1271,7 @@ def self.import_by_client(client_id: nil, total_count: nil)
end

count += dois.length
Rails.logger.info "[Elasticsearch] Imported #{count} DOIs for repository #{client_id}." if total_count > 500
Rails.logger.info "[Elasticsearch] Imported #{count} DOIs for repository #{client_id}."
end

if errors > 1
Expand Down

0 comments on commit 30b600d

Please sign in to comment.