Class: Karafka::Params::Interchanger

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/params/interchanger.rb

Overview

Interchangers allow us to format/encode/pack data that is being send to perform_async This is meant to target mostly issues with data encoding like this one: github.com/mperham/sidekiq/issues/197 Each custom interchanger should implement following methods:

- load - it is meant to encode params before they get stored inside Redis
- parse - decoded params back to a hash format that we can use

Class Method Summary collapse

Class Method Details

.load(params) ⇒ Karafka::Params::Params

Note:

Params might not be parsed because of lazy loading feature. If you implement your own interchanger logic, this method needs to return data that can be converted to json with default Sidekiqs logic

Returns same as input. We assume that our incoming data is jsonable-safe and we can rely on a direct Sidekiq encoding logic.

Parameters:

Returns:

  • (Karafka::Params::Params)

    same as input. We assume that our incoming data is jsonable-safe and we can rely on a direct Sidekiq encoding logic



17
18
19
# File 'lib/karafka/params/interchanger.rb', line 17

def load(params)
  params
end

.parse(params) ⇒ Hash

Note:

Hash is what we need to build Karafka::Params::Params, so we do nothing with it. If you implement your own interchanger logic, this method needs to return a hash with appropriate data that will be used to build Karafka::Params::Params

Returns We return exactly what we received. We rely on sidekiqs default interchanging format.

Parameters:

  • params (Hash)

    Sidekiqs params that are now a Hash (after they were JSON#parse)

Returns:

  • (Hash)

    We return exactly what we received. We rely on sidekiqs default interchanging format



27
28
29
# File 'lib/karafka/params/interchanger.rb', line 27

def parse(params)
  params
end