Class: Sidekiq::Extensions::Proxy

Inherits:
BasicObject
Defined in:
lib/sidekiq/extensions/generic_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(performable, target, options = {}) ⇒ Proxy

Returns a new instance of Proxy.



9
10
11
12
13
# File 'lib/sidekiq/extensions/generic_proxy.rb', line 9

def initialize(performable, target, options={})
  @performable = performable
  @target = target
  @opts = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sidekiq/extensions/generic_proxy.rb', line 15

def method_missing(name, *args)
  # Sidekiq has a limitation in that its message must be JSON.
  # JSON can't round trip real Ruby objects so we use YAML to
  # serialize the objects to a String.  The YAML will be converted
  # to JSON and then deserialized on the other side back into a
  # Ruby object.
  obj = [@target, name, args]
  marshalled = ::YAML.dump(obj)
  if marshalled.size > SIZE_LIMIT
    ::Sidekiq.logger.warn { "#{@target}.#{name} job argument is #{marshalled.bytesize} bytes, you should refactor it to reduce the size" }
  end
  @performable.client_push({ 'class' => @performable, 'args' => [marshalled] }.merge(@opts))
end