app/models/concerns/spree/callbackable.rb in solidus_recommendations-0.0.1 vs app/models/concerns/spree/callbackable.rb in solidus_recommendations-0.0.2

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true module Spree module Callbackable extend ActiveSupport::Concern included do @@ -7,23 +8,28 @@ after_commit :index_document, on: :create after_commit :update_document, on: :update after_commit :delete_document, on: :destroy - delegate :delete_document, to: :__elasticsearch__ - ## # Index document into elasticsearch # - def index_document - __elasticsearch__.index_document(version_options) - end + delegate :index_document, to: :__elasticsearch__ ## # Updates elasticsearch document from featured model # def update_document - __elasticsearch__.update_document(version_options) + __elasticsearch__.update_document + rescue Elasticsearch::Transport::Transport::Errors::NotFound + Rails.logger.warn "[#{self.class}] Document with id #{id} not found on elasticsearch cluster" + __elasticsearch__.index_document + end + + def delete_document + __elasticsearch__.delete_document + rescue Elasticsearch::Transport::Transport::Errors::NotFound + Rails.logger.warn "[#{self.class}] Document with id #{id} not found on elasticsearch cluster" end private def version_options