Module: Esse::AsyncIndexing::Workers

Defined in:
lib/esse/async_indexing.rb,
lib/esse/async_indexing/workers.rb,
lib/esse/async_indexing/workers/faktory.rb,
lib/esse/async_indexing/workers/sidekiq.rb,
lib/esse/async_indexing/workers/shared_class_methods.rb

Defined Under Namespace

Modules: Faktory, SharedClassMethods, Sidekiq

Constant Summary collapse

DEFAULT =
{
  "esse/async_indexing/jobs/bulk_update_lazy_document_attribute_job" => "Esse::AsyncIndexing::Jobs::BulkUpdateLazyDocumentAttributeJob",
  "esse/async_indexing/jobs/document_delete_by_id_job" => "Esse::AsyncIndexing::Jobs::DocumentDeleteByIdJob",
  "esse/async_indexing/jobs/document_index_by_id_job" => "Esse::AsyncIndexing::Jobs::DocumentIndexByIdJob",
  "esse/async_indexing/jobs/document_update_by_id_job" => "Esse::AsyncIndexing::Jobs::DocumentUpdateByIdJob",
  "esse/async_indexing/jobs/document_upsert_by_id_job" => "Esse::AsyncIndexing::Jobs::DocumentUpsertByIdJob",
  "esse/async_indexing/jobs/import_all_job" => "Esse::AsyncIndexing::Jobs::ImportAllJob",
  "esse/async_indexing/jobs/import_batch_id_job" => "Esse::AsyncIndexing::Jobs::ImportBatchIdJob",
  "esse/async_indexing/jobs/update_lazy_document_attribute_job" => "Esse::AsyncIndexing::Jobs::UpdateLazyDocumentAttributeJob"
}

Class Method Summary collapse

Class Method Details

.for(service, **options) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/esse/async_indexing/workers.rb', line 33

def self.for(service, **options)
  require_relative "workers/#{service}"
  service = service.to_sym
  worker_options = options.merge(service: service)
  module_name = service.to_s.split(/_/i).collect! { |w| w.capitalize }.join
  mod = Esse::AsyncIndexing::Workers.const_get(module_name)
  mod.module_eval do
    define_method(:bg_worker_options) do
      worker_options
    end
  end
  mod
end

.install!(service, **options) ⇒ Object

The backend service may live in a different application, so they are not required by default. That’s why we have a separate structure to let enqueue jobs even without having the explicit worker class loaded. This method will require all the internal jobs and configure them according to the defined options.



22
23
24
25
26
27
28
29
30
31
# File 'lib/esse/async_indexing/workers.rb', line 22

def self.install!(service, **options)
  return if @installed_services&.include?(service.to_sym)

  DEFAULT.each do |job, worker_name|
    Kernel.require(job)
    worker = Esse::AsyncIndexing::Jobs.const_get(worker_name.split("::").last)
    worker.extend(self.for(service, **options))
  end
  @installed_services = Array(@installed_services) << service.to_sym
end