Class: Wurk::Middleware::CurrentAttributes::Save

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

Overview

Client-side: snapshot each registered CurrentAttributes class into the job hash. Caller-supplied keys take precedence (||=), and a class with nothing set adds no key, so the payload doesn't grow an empty one.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(classes) ⇒ Save

Returns a new instance of Save.



72
73
74
# File 'lib/wurk/middleware/current_attributes.rb', line 72

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_class, job, _queue, _redis_pool) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/wurk/middleware/current_attributes.rb', line 76

def call(_job_class, job, _queue, _redis_pool)
  @classes.each_with_index do |reference, idx|
    attrs = CurrentAttributes.snapshot(CurrentAttributes.resolve(reference))
    job[CurrentAttributes.key_for(idx)] ||= attrs unless attrs.empty?
  end
  yield
end

#logger ⇒ Object Originally defined in module ServerMiddleware

#redis(idempotent: false) ⇒ Object Originally defined in module ServerMiddleware

#redis_pool ⇒ Object Originally defined in module ServerMiddleware