Class: Axn::Async::Adapters::Sidekiq::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/axn/async/adapters/sidekiq/worker.rb

Overview

Generic Sidekiq worker that runs ANY Axn action by name.

Actions no longer include Sidekiq::Job themselves. Enqueueing an action enqueues THIS worker with the action's class name + serialized kwargs; the worker constantizes the action and calls it.

Because the worker only needs .call (which every action has), the worker process never needs the async adapter applied to the action. That's what lets the action's new stay private AND makes the "rely on the global default in a fresh worker process" path work without any lazy reconfiguration.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._ensure_sidekiq_job!Object

Mixed in lazily so the const is definable regardless of axn/sidekiq load order (the adapter file is required unconditionally by the registry). Sidekiq is always present by the time the worker is actually enqueued or dispatched.



23
24
25
# File 'lib/axn/async/adapters/sidekiq/worker.rb', line 23

def self._ensure_sidekiq_job!
  include(::Sidekiq::Job) unless include?(::Sidekiq::Job)
end

Instance Method Details

#perform(action_class_name, job_kwargs = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/axn/async/adapters/sidekiq/worker.rb', line 28

def perform(action_class_name, job_kwargs = {})
  # Validate Sidekiq config once on first real execution (skipped in test modes).
  AutoConfigure.validate_configuration!(Axn.config.async_exception_reporting) unless AutoConfigure.skip_validation?

  action_class = action_class_name.constantize
  context = Axn::Internal::AsyncSerialization.deserialize(job_kwargs)

  result = action_class.call(**context)

  # Only re-raise unexpected exceptions so Sidekiq can retry.
  # Axn::Failure is a deliberate business decision (from fail!), not a transient error.
  raise result.exception if result.outcome.exception?

  result
end