From 3cd5d53e6f4c71977062bdbf0f59d5df653b25a5 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sat, 19 Dec 2020 19:42:52 +0100 Subject: [PATCH] better messaging during import. datacite/datacite#965 --- app/jobs/doi_not_indexed_job.rb | 4 ++-- app/models/client.rb | 4 ++-- app/models/doi.rb | 10 +++------- lib/tasks/client.rake | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/jobs/doi_not_indexed_job.rb b/app/jobs/doi_not_indexed_job.rb index 80b6d19fc..c9fa75152 100644 --- a/app/jobs/doi_not_indexed_job.rb +++ b/app/jobs/doi_not_indexed_job.rb @@ -3,7 +3,7 @@ class DoiNotIndexedJob < ApplicationJob queue_as :lupo_background - def perform(client_id, _options = {}) - Doi.import_by_client(client_id: client_id) + def perform(client_id, options = {}) + Doi.import_by_client(client_id, options) end end diff --git a/app/models/client.rb b/app/models/client.rb index 2c880d702..ef7cf6224 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -718,8 +718,8 @@ def self.import_dois_not_indexed(query: nil) # loop through repositories that have DOIs not indexed in Elasticsearch table.each do |row| - Rails.logger.info "Indexing #{row["DOIs in Database"]} DOIs (#{row["DOIs missing"]} missing) for repository #{row["Repository ID"]}." - DoiNotIndexedJob.perform_later(row["Repository ID"]) + Rails.logger.info "Started to import #{row["DOIs in Database"]} DOIs (#{row["DOIs missing"]} missing) for repository #{row["Repository ID"]}." + DoiNotIndexedJob.perform_later(row["Repository ID"], doi_count: row["DOIs in Database"], missing_count: row["DOIs missing"]) end end diff --git a/app/models/doi.rb b/app/models/doi.rb index 655988a54..790c2264e 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -1243,7 +1243,7 @@ def self.import_one(doi_id: nil) message end - def self.import_by_client(client_id: nil) + def self.import_by_client(client_id, options={}) client = ::Client.where(symbol: client_id).first return nil if client.blank? @@ -1271,14 +1271,10 @@ def self.import_by_client(client_id: nil) end count += dois.length - Rails.logger.info "[Elasticsearch] Imported #{count} DOIs for repository #{client_id}." + Rails.logger.info "[Elasticsearch] So far imported #{count} DOIs for repository #{client_id}." end - if errors > 1 - Rails.logger.error "[Elasticsearch] #{errors} errors importing #{count} DOIs for repository #{client_id}." - elsif count > 0 - Rails.logger.info "[Elasticsearch] Imported a total of #{count} DOIs for repository #{client_id}." - end + Rails.logger.info "[Elasticsearch] Imported a total of #{count} DOIs (#{options[:missing_count].to_i - errors} out of #{options[:missing_count].to_i} errors resolved) for repository #{client_id}." count rescue Elasticsearch::Transport::Transport::Errors::RequestEntityTooLarge, Faraday::ConnectionFailed, ActiveRecord::LockWaitTimeout => e diff --git a/lib/tasks/client.rake b/lib/tasks/client.rake index 7a9bada66..e9e4e2e4a 100644 --- a/lib/tasks/client.rake +++ b/lib/tasks/client.rake @@ -99,7 +99,7 @@ namespace :client do # import DOIs for client puts "#{client.dois.length} DOIs will be imported." - Doi.import_by_client(client_id: ENV["CLIENT_ID"]) + Doi.import_by_client(ENV["CLIENT_ID"]) end desc "Import dois not indexed"