Module: Esse::AsyncIndexing::ActiveRecord::Model::ClassMethods

Defined in:
lib/esse/async_indexing/active_record.rb

Instance Method Summary collapse

Instance Method Details

#async_index_callback(index_repo_name, on: %i[create update destroy],, with: nil, **options, &block) ⇒ Object

Define callback on create/update/delete to push a job to the async indexing the document.

Parameters:

  • index_repo_name (String)

    The path of index and repository name. For example a index with a single repository named ‘users` is `users`. And a index with multiple repositories named `animals` and `dog` as the repository name is `animals/dog`. For namespace, use `/` as the separator.

Raises:

  • (ArgumentError)

    when the repo and events are already registered

  • (ArgumentError)

    when the specified index have multiple repos



67
68
69
70
71
72
# File 'lib/esse/async_indexing/active_record.rb', line 67

def async_index_callback(index_repo_name, on: %i[create update destroy], with: nil, **options, &block)
  options[:service_name] = ::Esse::AsyncIndexing.service_name(options[:service_name])
  Array(on).each do |event|
    esse_callback(index_repo_name, :async_indexing, on: event, with: with, **options, &block)
  end
end

#async_update_lazy_attribute_callback(index_repo_name, attribute_name, on: %i[create update destroy],, **options, &block) ⇒ Object

Define callback on create/update/delete to push a job to the async update a lazy attribute.

Parameters:

  • index_repo_name (String)

    The path of index and repository name. For example a index with a single repository named ‘users` is `users`. And a index with multiple repositories named `animals` and `dog` as the repository name is `animals/dog`. For namespace, use `/` as the separator.

  • attribute_name (String, Symbol)

    The name of the lazy attribute to update.

Raises:

  • (ArgumentError)

    when the repo and events are already registered

  • (ArgumentError)

    when the specified index have multiple repos



83
84
85
86
87
# File 'lib/esse/async_indexing/active_record.rb', line 83

def async_update_lazy_attribute_callback(index_repo_name, attribute_name, on: %i[create update destroy], **options, &block)
  options[:attribute_name] = attribute_name
  options[:service_name] = ::Esse::AsyncIndexing.service_name(options[:service_name])
  esse_callback(index_repo_name, :async_update_lazy_attribute, identifier_suffix: attribute_name.to_sym, on: on, **options, &block)
end