Class: Magick::Rails::SubscriberMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/magick/rails/railtie.rb

Overview

Ensures each process (including Puma workers forked under preload_app!) has a live Redis Pub/Sub subscriber for cross-process cache invalidation. ensure_subscriber! returns immediately once @owner_pid == Process.pid, so the per-request cost is a single pid comparison after the first call.

Inside module Rails on purpose: the initializer above installs Magick::Rails::SubscriberMiddleware, and this class used to sit one level up as Magick::SubscriberMiddleware, so the first boot that actually loaded this file raised NameError.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ SubscriberMiddleware

Returns a new instance of SubscriberMiddleware.



166
167
168
# File 'lib/magick/rails/railtie.rb', line 166

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



170
171
172
173
174
175
176
177
178
# File 'lib/magick/rails/railtie.rb', line 170

def call(env)
  begin
    registry = Magick.adapter_registry
    registry.ensure_subscriber! if registry.respond_to?(:ensure_subscriber!)
  rescue StandardError
    # Best-effort: never break a request over subscriber bookkeeping.
  end
  @app.call(env)
end