Class: Wurk::Middleware::CurrentAttributes::Load
- Inherits:
-
Object
- Object
- Wurk::Middleware::CurrentAttributes::Load
- Includes:
- ServerMiddleware
- Defined in:
- lib/wurk/middleware/current_attributes.rb
Overview
Restores each registered CurrentAttributes class for the duration of the inner block, then resets so the next job in the thread starts clean. Reset runs in ‘ensure` to survive raises and Skip.
Instance Attribute Summary
Attributes included from ServerMiddleware
Instance Method Summary collapse
- #call(_job_or_class, job, _queue) ⇒ Object
-
#initialize(classes) ⇒ Load
constructor
A new instance of Load.
Methods included from ServerMiddleware
Constructor Details
#initialize(classes) ⇒ Load
Returns a new instance of Load.
72 73 74 |
# File 'lib/wurk/middleware/current_attributes.rb', line 72 def initialize(classes) @classes = classes end |
Instance Method Details
#call(_job_or_class, job, _queue) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/wurk/middleware/current_attributes.rb', line 76 def call(_job_or_class, job, _queue) @classes.each_with_index do |klass, idx| CurrentAttributes.restore(klass, job[CurrentAttributes.key_for(idx)]) end yield ensure @classes.each(&:reset) end |