Class: Sidekiq::Defer::Proxy

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

Instance Method Summary collapse

Constructor Details

#initialize(performable, target, **options) ⇒ Proxy

Returns a new instance of Proxy.



10
11
12
13
14
# File 'lib/sidekiq/defer/generic_proxy.rb', line 10

def initialize(performable, target, **options)
  @performable = performable
  @target = target
  @opts = options.transform_keys(&:to_s)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sidekiq/defer/generic_proxy.rb', line 20

def method_missing(name, *, **)
  # 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, [*], {**}]
  marshalled = ::YAML.dump(obj)
  print_warning(name, marshalled)

  @performable.client_push({"class" => @performable,
                            "args" => [marshalled],
                            "display_class" => "#{@target}.#{name}"}.merge(@opts))
end

Instance Method Details



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sidekiq/defer/generic_proxy.rb', line 35

def print_warning(name, dump)
  limited_payload_size = Defer.limit_payload_size
  return unless limited_payload_size

  size = (limited_payload_size != true) ? limited_payload_size : DEFAULT_SIZE_LIMIT
  return if dump.size <= size

  ::Sidekiq.logger.warn do
    "#{@target}.#{name} job argument is #{dump.bytesize} bytes, you should refactor it to reduce the size"
  end
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/sidekiq/defer/generic_proxy.rb', line 16

def respond_to_missing?
  true
end