Sha256: 8f85d22a511d33592f497be69e3642423189008a9ad4864f066ae7beca65820b

Contents?: true

Size: 1 KB

Versions: 27

Compression:

Stored size: 1 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] }.merge(@opts))
      end
    end

  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
sidekiq-5.2.10 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.2.9 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.2.8 lib/sidekiq/extensions/generic_proxy.rb
sidekiq_cleaner-5.3.8 lib/sidekiq/extensions/generic_proxy.rb
sidekiq_cleaner-5.3.6 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.2.7 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.2.6 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.2.5 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.2.4 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.2.3 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.2.2 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.2.1 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.2.0 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.1.3 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.1.2 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.1.1 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.1.0 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.0.5 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.0.4 lib/sidekiq/extensions/generic_proxy.rb
sidekiq-5.0.3 lib/sidekiq/extensions/generic_proxy.rb