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 puts back whatever was there before — not a
blanket reset. On a server thread the prior state is empty, so this is
equivalent to resetting; but Load also runs on the CLIENT chain (persist
registers it on both), where an enqueue happens mid-request with
request-scoped attributes already set. Resetting there would wipe the
caller's state right after perform_async. Save/restore is what Sidekiq
does and is correct on both chains. Restore runs in ensure to survive
raises and Skip.
Registered on BOTH chains, so call takes an optional 4th arg: the
client chain passes a redis_pool, the server chain stops at queue.
Instance Attribute Summary collapse
-
#config ⇒ Object
included
from ServerMiddleware
Returns the value of attribute config.
Instance Method Summary collapse
- #call(_job_or_class, job, _queue, _redis_pool = nil) ⇒ Object
-
#initialize(classes) ⇒ Load
constructor
A new instance of Load.
- #logger ⇒ Object included from ServerMiddleware
- #redis(idempotent: false) ⇒ Object included from ServerMiddleware
- #redis_pool ⇒ Object included from ServerMiddleware
Constructor Details
#initialize(classes) ⇒ Load
Returns a new instance of Load.
100 101 102 |
# File 'lib/wurk/middleware/current_attributes.rb', line 100 def initialize(classes) @classes = classes end |
Instance Attribute Details
#config ⇒ Object Originally defined in module ServerMiddleware
Returns the value of attribute config.
Instance Method Details
#call(_job_or_class, job, _queue, _redis_pool = nil) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/wurk/middleware/current_attributes.rb', line 104 def call(_job_or_class, job, _queue, _redis_pool = nil) classes = @classes.map { |reference| CurrentAttributes.resolve(reference) } previous = classes.map { |klass| CurrentAttributes.snapshot(klass) } classes.each_with_index do |klass, idx| CurrentAttributes.restore(klass, job[CurrentAttributes.key_for(idx)]) end yield ensure previous&.each_with_index do |attrs, idx| classes[idx].reset CurrentAttributes.restore(classes[idx], attrs) end end |