Module: Esse::AsyncIndexing
- Defined in:
- lib/esse/async_indexing/workers/shared_class_methods.rb,
lib/esse/async_indexing.rb,
lib/esse/async_indexing.rb,
lib/esse/async_indexing/cli.rb,
lib/esse/async_indexing/config.rb,
lib/esse/async_indexing/errors.rb,
lib/esse/async_indexing/worker.rb,
lib/esse/async_indexing/actions.rb,
lib/esse/async_indexing/testing.rb,
lib/esse/async_indexing/version.rb,
lib/esse/async_indexing/workers.rb,
lib/esse/async_indexing/adapters.rb,
lib/esse/async_indexing/active_record.rb,
lib/esse/async_indexing/configuration.rb,
lib/esse/async_indexing/workers/faktory.rb,
lib/esse/async_indexing/workers/sidekiq.rb,
lib/esse/async_indexing/adapters/adapter.rb,
lib/esse/async_indexing/adapters/faktory.rb,
lib/esse/async_indexing/adapters/sidekiq.rb,
lib/esse/async_indexing/configuration/faktory.rb,
lib/esse/async_indexing/configuration/sidekiq.rb,
lib/esse/async_indexing/active_record_callbacks/callback.rb,
lib/esse/async_indexing/active_record_callbacks/on_create.rb,
lib/esse/async_indexing/active_record_callbacks/on_update.rb,
lib/esse/async_indexing/active_record_callbacks/on_destroy.rb,
lib/esse/async_indexing/active_record_callbacks/lazy_update_attribute.rb
Overview
frizen_string_literal: true
Defined Under Namespace
Modules: Actions, ActiveRecord, ActiveRecordCallbacks, Adapters, CLI, Config, Jobs, JobsInterceptorAdapter, Workers
Classes: ConfigService, Configuration, Error, NotDefinedWorkerError, Testing, Worker
Constant Summary
collapse
- SERVICES =
{
sidekiq: Adapters::Sidekiq,
faktory: Adapters::Faktory
}
- VERSION =
"0.0.2"
- ESSE_ACTIVE_RECORD_MINIMAL_VERSION =
::Gem::Version.new("0.3.5")
Class Method Summary
collapse
Class Method Details
.__register_active_record_callbacks! ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/esse/async_indexing/active_record.rb', line 24
def self.__register_active_record_callbacks!
callbacks = Esse::ActiveRecord::Callbacks
unless callbacks.registered?(:async_indexing, :create)
callbacks.register_callback(:async_indexing, :create, Esse::AsyncIndexing::ActiveRecordCallbacks::OnCreate)
end
unless callbacks.registered?(:async_indexing, :update)
callbacks.register_callback(:async_indexing, :update, Esse::AsyncIndexing::ActiveRecordCallbacks::OnUpdate)
end
unless callbacks.registered?(:async_indexing, :destroy)
callbacks.register_callback(:async_indexing, :destroy, Esse::AsyncIndexing::ActiveRecordCallbacks::OnDestroy)
end
unless callbacks.registered?(:async_update_lazy_attribute, :create)
callbacks.register_callback(:async_update_lazy_attribute, :create, Esse::AsyncIndexing::ActiveRecordCallbacks::LazyUpdateAttribute)
end
unless callbacks.registered?(:async_update_lazy_attribute, :update)
callbacks.register_callback(:async_update_lazy_attribute, :update, Esse::AsyncIndexing::ActiveRecordCallbacks::LazyUpdateAttribute)
end
unless callbacks.registered?(:async_update_lazy_attribute, :destroy)
callbacks.register_callback(:async_update_lazy_attribute, :destroy, Esse::AsyncIndexing::ActiveRecordCallbacks::LazyUpdateAttribute)
end
end
|
.__validate_active_record_version! ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/esse/async_indexing/active_record.rb', line 7
def self.__validate_active_record_version!
unless defined?(Esse::ActiveRecord::Callbacks)
raise <<~MSG
To use async indexing ActiveRecord callbacks you need to install and require the `esse-active_record` gem.
Add this line to your application's Gemfile:
gem 'esse-active_record', '~> 0.3.5'
MSG
end
require "esse/active_record/version"
if ::Gem::Version.new(Esse::ActiveRecord::VERSION) < ESSE_ACTIVE_RECORD_MINIMAL_VERSION
raise <<~MSG
The esse-active_record gem version #{ESSE_ACTIVE_RECORD_MINIMAL_VERSION} or higher is required. Please update the gem to the latest version.
MSG
end
end
|
.async_indexing_repo?(repo) ⇒ Boolean
62
63
64
65
66
|
# File 'lib/esse/async_indexing.rb', line 62
def self.async_indexing_repo?(repo)
return false unless repo.is_a?(Class) && repo < Esse::Repository
repo.respond_to?(:implement_batch_ids?) && repo.implement_batch_ids?
end
|
.jid ⇒ Object
58
59
60
|
# File 'lib/esse/async_indexing.rb', line 58
def self.jid
SecureRandom.hex(12)
end
|
.service_name(identifier = nil) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/esse/async_indexing.rb', line 45
def self.service_name(identifier = nil)
identifier ||= Esse.config.async_indexing.services.first
if identifier.nil?
raise ArgumentError, "There are no async indexing services configured. Please configure at least one service or pass the service name as an argument."
end
if SERVICES[identifier.to_sym].nil?
raise ArgumentError, "Invalid service: #{identifier.inspect}, valid services are: #{SERVICES.keys.join(", ")}"
end
identifier.to_sym
end
|
Returns An instance of worker.
40
41
42
43
|
# File 'lib/esse/async_indexing.rb', line 40
def self.worker(worker_class, service: nil, **options)
serv_name = service_name(service)
Worker.new(worker_class, **Esse.config.async_indexing.send(service).worker_options(worker_class).merge(options), service: serv_name)
end
|