class Sidekiq::Dry::Client::SerializationMiddleware

Middleware which converts `Dry::Struct` job arguments to hashes with a `_type` key to help deserializing back to the initial struct

Public Instance Methods

call(_worker_class, job, _queue, _redis_pool) { || ... } click to toggle source
# File lib/sidekiq/dry/client/serialization_middleware.rb, line 9
def call(_worker_class, job, _queue, _redis_pool)
  job['args'].map! do |arg|
    # Don't mutate non-struct arguments
    next arg unless arg.is_a? ::Dry::Struct

    # Set a `_type` argument to be able to instantiate
    # the struct when the job is performed
    arg.to_h.merge(_type: arg.class)
  end

  yield
end