Class: Sidekiq::DelayExtensions::GenericProxy
- Inherits:
- BasicObject
- Defined in:
- lib/sidekiq/delay_extensions/generic_proxy.rb
Instance Method Summary collapse
-
#initialize(performable, target, options = {}) ⇒ GenericProxy
constructor
A new instance of GenericProxy.
-
#method_missing(name, *args, **kwargs) ⇒ Object
rubocop:disable Style/MissingRespondToMissing.
Constructor Details
#initialize(performable, target, options = {}) ⇒ GenericProxy
Returns a new instance of GenericProxy.
37 38 39 40 41 |
# File 'lib/sidekiq/delay_extensions/generic_proxy.rb', line 37 def initialize(performable, target, = {}) @performable = performable @target = target @opts = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs) ⇒ Object
rubocop:disable Style/MissingRespondToMissing
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sidekiq/delay_extensions/generic_proxy.rb', line 43 def method_missing(name, *args, **kwargs) # rubocop:disable Style/MissingRespondToMissing begin has_no_kwargs = kwargs.nil? || kwargs.empty? valid_json_args = if has_no_kwargs # if args.last.is_a?(Hash) && args.last.keys.any? { |key| key.is_a?(Symbol) } # kwargs = args.pop.symbolize_keys [*args] else [*args, ::JSON.parse(::JSON.dump(kwargs))] end obj = [@target.name, name&.to_s, valid_json_args] marshalled = ::JSON.dump(obj) rescue ::JSON::ParserError obj = if kwargs&.any? [@target.name, name&.to_s, *args, **kwargs] else [@target.name, name&.to_s, *args] end ::Sidekiq.logger.warn { "Non-JSON args passed to Sidekiq delayed job. obj=#{obj.inspect}" } marshalled = ::YAML.dump(obj) end # Debug notes: # marshalled = ::YAML.dump(valid_json_args) # marshalled = ::YAML.to_json(valid_json_args) # value = { # target_name: @target.name, # name: name, # args: args, # kwargs: kwargs, # valid_json_args: valid_json_args, # obj: obj, # marshalled: marshalled, # } # ::STDOUT.puts value.inspect 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 valid_opts = @opts.stringify_keys @performable.client_push({"class" => @performable, "args" => [marshalled], "display_class" => "#{@target}.#{name}"}.merge(valid_opts)) end |