Module: Axn::Async::Adapters::Sidekiq
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/axn/async/adapters/sidekiq.rb,
lib/axn/async/adapters/sidekiq/worker.rb,
lib/axn/async/adapters/sidekiq/middleware.rb,
lib/axn/async/adapters/sidekiq/death_handler.rb,
lib/axn/async/adapters/sidekiq/retry_helpers.rb,
lib/axn/async/adapters/sidekiq/auto_configure.rb
Defined Under Namespace
Modules: AutoConfigure, DeathHandler, RetryHelpers Classes: ConfigurationError, Middleware, Worker
Class Method Summary collapse
-
._configure_action!(action) ⇒ Object
Per-action setup, invoked from Axn::Async#async on every explicit
async :sidekiqdeclaration (so subclasses that re-declare get their own worker even thoughincludeis a no-op for them). - ._running_in_background? ⇒ Boolean
-
.configure_default_worker!(config: {}, block: nil) ⇒ Object
Build/refresh the worker used for the GLOBAL DEFAULT path.
-
.default_worker ⇒ Object
The worker for the global-default path, built on demand if set_default_async hasn't yet.
-
.job_tags_for(facets) ⇒ Object
Format a resolved facet map (=> scalar-or-array-of-scalars) into Sidekiq job-tag strings in "name:value" form.
Class Method Details
._configure_action!(action) ⇒ Object
Per-action setup, invoked from Axn::Async#async on every explicit async :sidekiq
declaration (so subclasses that re-declare get their own worker even though include
is a no-op for them). Builds a per-action AxnSidekiqWorker subclass carrying the
action's kwargs + block; skipped for the global-default path (those use DefaultWorker).
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/axn/async/adapters/sidekiq.rb', line 58 def self._configure_action!(action) return if action._async_via_default Worker._ensure_sidekiq_job! # Build a FRESH subclass each declaration (own const per class in a hierarchy, and no # stale options carried over if async is re-declared with different config). sidekiq_options # merges, so reusing an existing subclass would silently retain prior settings. action.send(:remove_const, :AxnSidekiqWorker) if action.const_defined?(:AxnSidekiqWorker, false) subclass = action.const_set(:AxnSidekiqWorker, Class.new(Worker)) # Block first, then kwargs override — `async :sidekiq, queue: "x" do sidekiq_options queue: "y" end` # resolves to "x" (the keyword wins), matching the pre-refactor adapter's precedence. subclass.class_eval(&action._async_config_block) if action._async_config_block subclass.(**action._async_config) if action._async_config&.any? subclass end |
._running_in_background? ⇒ Boolean
16 17 18 |
# File 'lib/axn/async/adapters/sidekiq.rb', line 16 def self._running_in_background? defined?(::Sidekiq) && ::Sidekiq.server? end |
.configure_default_worker!(config: {}, block: nil) ⇒ Object
Build/refresh the worker used for the GLOBAL DEFAULT path. It carries the default's
kwargs + block (block first, kwargs override — matching the explicit-async precedence)
on a DEDICATED subclass, so explicit per-action workers (which subclass the pristine
Worker) never inherit global-default config. Called from Configuration#set_default_async,
which runs at boot in every process — so this named const exists (a worker can
constantize it) and carries the full config including server-side hooks like
sidekiq_retry_in, regardless of load order or whether any action declares async :sidekiq.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/axn/async/adapters/sidekiq.rb', line 27 def self.configure_default_worker!(config: {}, block: nil) return unless defined?(::Sidekiq::Job) Worker._ensure_sidekiq_job! send(:remove_const, :DefaultWorker) if const_defined?(:DefaultWorker, false) worker = const_set(:DefaultWorker, Class.new(Worker)) worker.class_eval(&block) if block worker.(**config) if config&.any? worker end |
.default_worker ⇒ Object
The worker for the global-default path, built on demand if set_default_async hasn't yet.
39 40 41 42 43 |
# File 'lib/axn/async/adapters/sidekiq.rb', line 39 def self.default_worker return const_get(:DefaultWorker, false) if const_defined?(:DefaultWorker, false) configure_default_worker!(config: Axn.config._default_async_config, block: Axn.config._default_async_config_block) end |
.job_tags_for(facets) ⇒ Object
Format a resolved facet map (=> scalar-or-array-of-scalars) into Sidekiq job-tag strings in "name:value" form. Array-valued facets fan out to one tag per element. Values are already coerced to legal scalars by Core::Tagging.coerce, so this only stringifies.
48 49 50 51 52 |
# File 'lib/axn/async/adapters/sidekiq.rb', line 48 def self.(facets) facets.flat_map do |name, value| Array(value).map { |element| "#{name}:#{element}" } end end |