diff --git a/app/jobs/index_background_job.rb b/app/jobs/index_background_job.rb new file mode 100644 index 000000000..22c1bfda8 --- /dev/null +++ b/app/jobs/index_background_job.rb @@ -0,0 +1,11 @@ +class IndexBackgroundJob < ActiveJob::Base + queue_as :lupo_background + + rescue_from ActiveJob::DeserializationError, Elasticsearch::Transport::Transport::Errors::BadRequest do |error| + Rails.logger.error error.message + end + + def perform(obj) + obj.__elasticsearch__.index_document + end +end diff --git a/app/jobs/index_job.rb b/app/jobs/index_job.rb index 5b2803300..e4205a44e 100644 --- a/app/jobs/index_job.rb +++ b/app/jobs/index_job.rb @@ -8,4 +8,4 @@ class IndexJob < ActiveJob::Base def perform(obj) obj.__elasticsearch__.index_document end -end \ No newline at end of file +end diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 9d6afad8f..1eb395685 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -10,19 +10,12 @@ module Indexable if self.class.name == "Doi" update_column(:indexed, Time.zone.now) send_import_message(self.to_jsonapi) if aasm_state == "findable" && !Rails.env.test? && !%w(crossref medra kisti jalc op).include?(client.symbol.downcase.split(".").first) - # elsif self.class.name == "Event" - # # reindex dois associated with Event - # @source_doi = Doi.where(doi: source_doi).first if source_doi - # IndexJob.perform_later(@source_doi) if @source_doi - - # @target_doi = Doi.where(doi: target_doi).first if target_doi - # IndexJob.perform_later(@target_doi) if @target_doi end end after_touch do # use index_document instead of update_document to also update virtual attributes - IndexJob.perform_later(self) + IndexBackgroundJob.perform_later(self) end before_destroy do diff --git a/app/models/event.rb b/app/models/event.rb index 82e77edf9..dbd02bb52 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -18,6 +18,9 @@ class Event < ActiveRecord::Base include Elasticsearch::Model + belongs_to :doi_for_source, class_name: "Doi", primary_key: :doi, foreign_key: :source_doi, touch: true, optional: true + belongs_to :doi_for_target, class_name: "Doi", primary_key: :doi, foreign_key: :target_doi, touch: true, optional: true + before_validation :set_defaults before_create :set_source_and_target_doi