Class: SidekiqCurrentModelMiddleware::Load

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::ServerMiddleware
Defined in:
lib/sidekiq_current_model_middleware.rb

Overview

Load class

Server middleware that loads CurrentAttributes from the Sidekiq job payload. It handles deserialization of ActiveRecord models using GlobalID.

Instance Method Summary collapse

Constructor Details

#initialize(cattrs) ⇒ Load

Initialize the Load middleware

Parameters:

  • cattrs (Hash)

    A hash of CurrentAttributes classes to load



95
96
97
# File 'lib/sidekiq_current_model_middleware.rb', line 95

def initialize(cattrs)
  @cattrs = cattrs
end

Instance Method Details

#call(_, job, _, &block) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/sidekiq_current_model_middleware.rb', line 99

def call(_, job, _, &block)
  klass_attrs = {}

  @cattrs.each do |(key, strklass)|
    next unless job.key?(key)

    klass_attrs[strklass.constantize] = job[key]
  end

  wrap(klass_attrs.to_a, &block)
end