Skip to content

Commit

Permalink
better logging. #690
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 21, 2020
1 parent 3079690 commit 19bafb2
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1249,12 +1249,14 @@ def self.import_one(doi_id: nil, id: nil)
end

def self.import_by_ids(options = {})
model = options[:model] || "Doi"

# TODO remove query for type once STI is enabled
if options[:model] = "DataciteDoi"
if model == "DataciteDoi"
collection = DataciteDoi.where(type: "DataciteDoi")
elsif options[:model] = "OtherDoi"
elsif model == "OtherDoi"
collection = OtherDoi.where(type: "OtherDoi")
elsif options[:model] = "Client"
elsif model == "Client"
client = ::Client.where(symbol: options[:client_id]).first
return nil if client.blank?

Expand All @@ -1278,7 +1280,7 @@ def self.import_by_ids(options = {})
DoiImportByIdJob.perform_later(options.merge(id: id))
unless Rails.env.test?
Rails.
logger.info "Queued importing for #{options[:model]} DOIs with IDs starting with #{
logger.info "Queued importing for #{model} DOIs with IDs starting with #{
id
}."
end
Expand All @@ -1291,11 +1293,12 @@ def self.import_by_id(options = {})
return nil if options[:id].blank?

id = options[:id].to_i
model = options[:model] || "Doi"
errors = 0
count = 0

# TODO remove query for type once STI is enabled
if options[:model] = "DataciteDoi"
if model == "DataciteDoi"
collection = DataciteDoi.where(type: "DataciteDoi")
index = if Rails.env.test?
"dois-test"
Expand All @@ -1304,7 +1307,7 @@ def self.import_by_id(options = {})
else
"dois"
end
elsif options[:model] = "OtherDoi"
elsif model == "OtherDoi"
collection = OtherDoi.where(type: "OtherDoi")
index = if Rails.env.test?
"dois-other-test"
Expand All @@ -1313,7 +1316,7 @@ def self.import_by_id(options = {})
else
"dois-other"
end
elsif options[:model] = "Client"
elsif model == "Client"
client = ::Client.where(symbol: options[:client_id]).first
return nil if client.blank?

Expand Down Expand Up @@ -1369,11 +1372,11 @@ def self.import_by_id(options = {})
if errors > 1
Rails.logger.error "[Elasticsearch] #{errors} errors importing #{
count
} #{collection} DOIs with IDs #{id} - #{id + 499}."
} #{model} DOIs with IDs #{id} - #{id + 499}."
elsif count > 0
Rails.logger.info "[Elasticsearch] Imported #{
count
} #{collection} DOIs with IDs #{id} - #{id + 499}."
} #{model} DOIs with IDs #{id} - #{id + 499}."
end

count
Expand All @@ -1382,7 +1385,7 @@ def self.import_by_id(options = {})
ActiveRecord::LockWaitTimeout => e
Rails.logger.info "[Elasticsearch] Error #{
e.message
} importing #{collection} DOIs with IDs #{id} - #{id + 499}."
} importing #{model} DOIs with IDs #{id} - #{id + 499}."

count = 0

Expand All @@ -1394,7 +1397,7 @@ def self.import_by_id(options = {})

Rails.logger.info "[Elasticsearch] Imported #{
count
} #{collection} DOIs with IDs #{id} - #{id + 499}."
} #{model} DOIs with IDs #{id} - #{id + 499}."

count
end
Expand Down

0 comments on commit 19bafb2

Please sign in to comment.