Class: Sidekiq::CurrentAttributes::Save
- Inherits:
-
Object
- Object
- Sidekiq::CurrentAttributes::Save
- Includes:
- ServerMiddleware
- Defined in:
- lib/sidekiq/middleware/current_attributes.rb
Instance Attribute Summary
Attributes included from ServerMiddleware
Instance Method Summary collapse
- #call(_, job, _, _) ⇒ Object
-
#initialize(cattrs) ⇒ Save
constructor
A new instance of Save.
Methods included from ServerMiddleware
Constructor Details
#initialize(cattrs) ⇒ Save
Returns a new instance of Save.
26 27 28 |
# File 'lib/sidekiq/middleware/current_attributes.rb', line 26 def initialize(cattrs) @cattrs = cattrs end |
Instance Method Details
#call(_, job, _, _) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sidekiq/middleware/current_attributes.rb', line 30 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 if attrs.any? # Older rails has a bug that `CurrentAttributes#attributes` always returns # the same hash instance. We need to dup it to avoid being accidentally mutated. job[key] = if returns_same_object? attrs.dup else attrs end end end end yield end |