mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
0a4de94d76
* Add keyword arguments support in extensions * Check that keywords arguments are passed * Test perform calls with keyword arguments * Fix kwargs forwarding on Ruby 2.6
33 lines
1.1 KiB
Ruby
33 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "yaml"
|
|
|
|
module Sidekiq
|
|
module Extensions
|
|
SIZE_LIMIT = 8_192
|
|
|
|
class Proxy < BasicObject
|
|
def initialize(performable, target, options = {})
|
|
@performable = performable
|
|
@target = target
|
|
@opts = options
|
|
end
|
|
|
|
def method_missing(name, *args, **kwargs)
|
|
# 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, kwargs]
|
|
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],
|
|
"display_class" => "#{@target}.#{name}"}.merge(@opts))
|
|
end
|
|
end
|
|
end
|
|
end
|