Sha256: 9cd6f64d114c5268d74a4f099673352ea3eccd6bf8289711255d01ef78f7c189

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

# 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)
        # 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],
                                  "display_class" => "#{@target}.#{name}"}.merge(@opts))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sidekiq-6.4.1 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-6.3.1 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-6.3.0 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-6.2.2 lib/sidekiq/extensions/generic_proxy.rb