Class: Sidekiq::CurrentAttributes::Save

Inherits:
Object
  • Object
show all
Includes:
ServerMiddleware
Defined in:
lib/sidekiq/middleware/current_attributes.rb

Instance Attribute Summary

Attributes included from ServerMiddleware

#config

Instance Method Summary collapse

Methods included from ServerMiddleware

#logger, #redis, #redis_pool

Constructor Details

#initialize(cattrs) ⇒ Save

Returns a new instance of Save.



24
25
26
# File 'lib/sidekiq/middleware/current_attributes.rb', line 24

def initialize(cattrs)
  @cattrs = cattrs
end

Instance Method Details

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



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sidekiq/middleware/current_attributes.rb', line 28

def call(_, job, _, _)
  @cattrs.each do |(key, strklass)|
    if !job.has_key?(key)
      attrs = strklass.constantize.attributes
      # Retries can push the job N times, we don't
      # want retries to reset cattr. #5692, #5090
      job[key] = attrs if attrs.any?
    end
  end
  yield
end