From 40fe0b675f4b33cf4f1d8bfed3a0f499361c4079 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 23 Jun 2019 23:49:48 +0200 Subject: [PATCH] error logging for crossref doi creation. datacite/levrieo#56 --- app/models/event.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/event.rb b/app/models/event.rb index bf1933119..02e2f09f5 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -314,7 +314,7 @@ def self.update_datacite_crossref(options={}) response = Event.query(nil, source_id: "datacite-crossref", page: { size: 1, cursor: cursor }) logger.info "[Update] #{response.results.total} events for source datacite-crossref." - # walk through results using cursor + # walk through results using cursor if response.results.total > 0 while response.results.results.length > 0 do response = Event.query(nil, source_id: "datacite-crossref", page: { size: size, cursor: cursor }) @@ -332,6 +332,8 @@ def self.update_datacite_crossref(options={}) end def self.get_crossref_metadata(id) + logger = Logger.new(STDOUT) + doi = doi_from_url(id) return {} unless doi.present? @@ -341,7 +343,12 @@ def self.get_crossref_metadata(id) # otherwise store Crossref metadata with DataCite # using client crossref.citations and DataCite XML xml = Base64.strict_encode64(id) - Doi.create({ xml: xml, source: "levriero", event: "publish", client_id: "crossref.citations" }, :without_protection => true) + d = Doi.new({ xml: xml, source: "levriero", event: "publish", client_id: "crossref.citations" }, :without_protection => true) + if d.save + logger.info "Record for DOI #{doi} created." + else + logger.warn "[Error for #{doi}]: " + d.errors.inspect + end end end