Module: Alplus::Sidekiq

Defined in:
lib/alplus/sidekiq.rb

Overview

Optional Sidekiq integration. Namespaced under Alplus::Sidekiq (not top-level) so this file never collides with the real ::Sidekiq constant it wraps -- ErrorHandler below refers to it explicitly via ::Sidekiq wherever the ambiguity would otherwise resolve to Alplus::Sidekiq instead.

This whole file is safe to load unconditionally (it defines classes, nothing more) -- alplus.rb only require_relatives it when defined?(::Sidekiq) is already true, and install! itself re-checks that guard, so a host app that never loads the sidekiq gem never pays for or activates any of this. The gem's runtime dependency list stays empty either way (sidekiq is never required from here).

Defined Under Namespace

Classes: ErrorHandler

Class Method Summary collapse

Class Method Details

.install!Object

Idempotent: installs ErrorHandler onto Sidekiq's server middleware chain exactly once per process, even if called more than once (e.g. re-evaluated in a reloading dev environment).



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/alplus/sidekiq.rb', line 55

def install!
  return if @installed
  return unless defined?(::Sidekiq) && ::Sidekiq.respond_to?(:configure_server)

  ::Sidekiq.configure_server do |config|
    next unless config.respond_to?(:server_middleware)

    config.server_middleware do |chain|
      chain.add Alplus::Sidekiq::ErrorHandler unless chain.exists?(Alplus::Sidekiq::ErrorHandler)
    end
  end
  @installed = true
end

.reset!Object

Test-only: lets a spec re-drive install!. Not called by production code.



71
72
73
# File 'lib/alplus/sidekiq.rb', line 71

def reset!
  @installed = false
end