Class: Karafka::Interchanger
- Inherits:
-
Object
- Object
- Karafka::Interchanger
- Defined in:
- lib/karafka/interchanger.rb
Overview
Interchanger allows 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:
- encode - it is meant to encode params before they get stored inside Redis
- decode - decoded params back to a hash format that we can use
This interchanger uses default Sidekiq options to exchange data
Instance Method Summary collapse
-
#decode(params_batch) ⇒ Array<Hash>
Exactly what we’ve fetched from Sidekiq.
-
#encode(params_batch) ⇒ Array<Hash>
Array with hash built out of params data.
Instance Method Details
#decode(params_batch) ⇒ Array<Hash>
Returns exactly what we’ve fetched from Sidekiq.
26 27 28 |
# File 'lib/karafka/interchanger.rb', line 26 def decode(params_batch) params_batch end |
#encode(params_batch) ⇒ Array<Hash>
Returns Array with hash built out of params data.
15 16 17 18 19 20 21 22 |
# File 'lib/karafka/interchanger.rb', line 15 def encode(params_batch) params_batch.map do |param| { 'raw_payload' => param.raw_payload, 'metadata' => param..to_h } end end |