Class: Wurk::Middleware::CurrentAttributes::Load

Inherits:
Object
  • Object
show all
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

#config

Instance Method Summary collapse

Methods included from ServerMiddleware

#logger, #redis, #redis_pool

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