Skip to content

Commit

Permalink
include callbacks when importing metadata. #161
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 16, 2018
1 parent d54e44d commit 29303fe
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,10 @@ def self.import_one(doi: nil)
[a.to_sym, meta[a]]
end.to_h.merge(schema_version: meta["schema_version"] || "http://datacite.org/schema/kernel-4", version_info: meta["version"], xml: string)

# update_attributes will trigger validations and Elasticsearch indexing
doi.update_attributes(attrs)
logger.info "[MySQL] Imported metadata for DOI " + doi.doi + "."
rescue TypeError, NoMethodError => error
rescue TypeError, NoMethodError, ActiveRecord::LockWaitTimeout => error
logger.error "[MySQL] Error importing metadata for " + doi.doi + ": " + error.message
end

Expand Down Expand Up @@ -382,6 +383,7 @@ def self.import_by_day(options={})
[a.to_sym, meta[a]]
end.to_h.merge(schema_version: meta["schema_version"] || "http://datacite.org/schema/kernel-4", version_info: meta["version"], xml: string)

# update_columns will NOT trigger validations and Elasticsearch indexing
doi.update_columns(attrs)
rescue TypeError, NoMethodError, ActiveRecord::LockWaitTimeout => error
logger.error "[MySQL] Error importing metadata for " + doi.doi + ": " + error.message
Expand Down Expand Up @@ -411,7 +413,8 @@ def self.import_missing(options={})
[a.to_sym, meta[a]]
end.to_h.merge(schema_version: meta["schema_version"] || "http://datacite.org/schema/kernel-4", version_info: meta["version"], xml: string)

doi.update_columns(attrs)
# update_attributes will trigger validations and Elasticsearch indexing
doi.update_attributes(attrs)
rescue TypeError, NoMethodError, ActiveRecord::LockWaitTimeout => error
logger.error "[MySQL] Error importing metadata for " + doi.doi + ": " + error.message
else
Expand Down

0 comments on commit 29303fe

Please sign in to comment.