karafka-sidekiq-backend 1.2.0.beta2 → 1.2.0.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cbf46f4edac28d13fad77fc120bf92456e37380bcee52718713ad94f4e9a5f2
4
- data.tar.gz: 5da6e57d3f61b3d2f59410e78c7c94a1a26b04051714f2895f36ce00c2099e8c
3
+ metadata.gz: f1e9d5b7c2a522e2ff126eca4b34ffc37efe1d4e9117d6996daf6b9fd959f393
4
+ data.tar.gz: ecf5117a7726db83707021ffeeab152b51d0f1e044fae590c8f2018ed94d52c8
5
5
  SHA512:
6
- metadata.gz: c98cfa129b4733d21fa6fc0491ba522c89c5187fc1d1113b8256e9a980f50dba131353b61e37ee3f9867d8ad6e6a665abb0d2980ec3cff9bcab91fc3dfa9b53f
7
- data.tar.gz: 63fd8534461a01e418e365f13ad207cfad9d5f7dff24adc09b8b15301e22749b3ad2d49b38ead45a70628722af90d2e36f5d48f3ce1cdadf1783567a9304fc93
6
+ metadata.gz: 41ab55ab65c5750ae7d2b4a4ec844da5049612f4a8e59419177dd1e85a43ff4e992a622dc6be9ee335dffd8a39ae5526fb16eaf10af27981f5494106f132441a
7
+ data.tar.gz: af65c10503038935f1a892aef9a231611196ea8c06a683b54e3cd6cf07f944e91cce13f19832b49070e7850a65ffd790a822091eb002dc7dfc6c575bb311f874
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Karafka Sidekiq Backend
2
2
 
3
- ## 1.2.0.beta2
3
+ ## 1.2.0.beta3
4
+ - ```#load``` and ```#parse``` are renamed to ```#encode``` and ```#decode``` in interchangers
5
+ - Default interchanger is not Base64 Marshal dump
4
6
  - #274 - Rename controllers to consumers
5
7
  - Karafka 1.2 support
6
8
  - Parse data before pushing to Sidekiq
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-sidekiq-backend (1.2.0.beta2)
4
+ karafka-sidekiq-backend (1.2.0.beta3)
5
5
  karafka (>= 1.2.0.beta2)
6
6
  sidekiq (>= 4.2)
7
7
 
@@ -81,7 +81,7 @@ GEM
81
81
  multi_json (1.13.1)
82
82
  null-logger (0.1.4)
83
83
  rack (2.0.4)
84
- rack-protection (2.0.0)
84
+ rack-protection (2.0.1)
85
85
  rack
86
86
  rake (12.3.0)
87
87
  redis (4.0.1)
@@ -116,13 +116,12 @@ GEM
116
116
  timecop (0.9.1)
117
117
  tzinfo (1.2.5)
118
118
  thread_safe (~> 0.1)
119
- waterdrop (1.2.0.beta1)
120
- delivery_boy (>= 0.2.3)
119
+ waterdrop (1.2.0)
120
+ delivery_boy (~> 0.2)
121
121
  dry-configurable (~> 0.7)
122
122
  dry-monitor (~> 0.1)
123
123
  dry-validation (~> 0.11)
124
124
  null-logger
125
- ruby-kafka (>= 0.5.3)
126
125
 
127
126
  PLATFORMS
128
127
  ruby
data/README.md CHANGED
@@ -85,9 +85,9 @@ Note that even then, you need to specify a controller that will schedule a backg
85
85
  Custom workers need to provide a ```#perform_async``` method. It needs to accept two arguments:
86
86
 
87
87
  - ```topic_id``` - first argument is a current topic id from which a given message comes
88
- - ```params``` - all the params that came from Kafka + additional metadata. This data format might be changed if you use custom interchangers. Otherwise it will be an instance of Karafka::Params::Params.
88
+ - ```params_batch``` - all the params that came from Kafka + additional metadata. This data format might be changed if you use custom interchangers. Otherwise it will be an instance of Karafka::Params::ParamsBatch.
89
89
 
90
- Keep in mind, that params might be in two states: parsed or unparsed when passed to #perform_async. This means, that if you use custom interchangers and/or custom workers, you might want to look into Karafka's sources to see exactly how it works.
90
+ **Note**: If you use custom interchangers, keep in mind, that params inside params batch might be in two states: parsed or unparsed when passed to #perform_async. This means, that if you use custom interchangers and/or custom workers, you might want to look into Karafka's sources to see exactly how it works.
91
91
 
92
92
  ### Interchangers
93
93
 
@@ -95,29 +95,6 @@ Custom interchangers target issues with non-standard (binary, etc.) data that we
95
95
 
96
96
  **Warning**: if you decide to use slow interchangers, they might significantly slow down Karafka.
97
97
 
98
- ```ruby
99
- class Base64Interchanger
100
- class << self
101
- def load(params_batch)
102
- params_batch.map do |params|
103
- Base64.encode64(Marshal.dump(params))
104
- end
105
- end
106
-
107
- def parse(params_batch)
108
- params_batch.map do |params|
109
- Marshal.load(Base64.decode64(params))
110
- end
111
- end
112
- end
113
- end
114
-
115
- topic :binary_video_details do
116
- controller Videos::DetailsController
117
- interchanger Base64Interchanger
118
- end
119
- ```
120
-
121
98
  ## References
122
99
 
123
100
  * [Karafka framework](https://github.com/karafka/karafka)
@@ -5,7 +5,7 @@ module Karafka
5
5
  # Sidekiq backend that schedules stuff to Sidekiq worker for delayed execution
6
6
  module Sidekiq
7
7
  # Karafka Sidekiq backend version
8
- VERSION = '1.2.0.beta2'
8
+ VERSION = '1.2.0.beta3'
9
9
 
10
10
  # Enqueues the execution of perform method into a worker.
11
11
  # @note Each worker needs to have a class #perform_async method that will allow us to pass
@@ -13,10 +13,12 @@ module Karafka
13
13
  # params_batch as a second one (we pass topic to be able to build back the consumer
14
14
  # in the worker)
15
15
  def process
16
+ Karafka.monitor.instrument('backends.sidekiq.process', caller: self) do
16
17
  topic.worker.perform_async(
17
18
  topic.id,
18
- topic.interchanger.load(params_batch)
19
+ topic.interchanger.encode(params_batch)
19
20
  )
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -25,7 +25,7 @@ module Karafka
25
25
  def consumer(topic_id, params_batch)
26
26
  topic = Karafka::Routing::Router.find(topic_id)
27
27
  consumer = topic.consumer.new
28
- consumer.params_batch = topic.interchanger.parse(params_batch)
28
+ consumer.params_batch = topic.interchanger.decode(params_batch)
29
29
  consumer
30
30
  end
31
31
  end
@@ -5,38 +5,28 @@ module Karafka
5
5
  # This is meant to target mostly issues with data encoding like this one:
6
6
  # https://github.com/mperham/sidekiq/issues/197
7
7
  # Each custom interchanger should implement following methods:
8
- # - load - it is meant to encode params before they get stored inside Redis
9
- # - parse - decoded params back to a hash format that we can use
8
+ # - encode - it is meant to encode params before they get stored inside Redis
9
+ # - decode - decoded params back to a hash format that we can use
10
+ #
11
+ # This interchanger is not the fastets but it handles many unusual cases and deals well with
12
+ # more complex Ruby and Rails objects
10
13
  class Interchanger
11
14
  class << self
12
15
  # @param params_batch [Karafka::Params::ParamsBatch] Karafka params batch object
13
16
  # @note Params might not be parsed because of lazy loading feature. If you implement your
14
17
  # own interchanger logic, this method needs to return data that can be converted to
15
18
  # json with default Sidekiqs logic
16
- # @return [Karafka::Params::ParamsBatch] parsed params batch. There are too many problems
19
+ # @return [String] parsed params batch encoded into a string. There are too many problems
17
20
  # with passing unparsed data from Karafka to Sidekiq, to make it a default. In case you
18
21
  # need this, please implement your own interchanger.
19
- def load(params_batch)
20
- params_batch.parsed
22
+ def encode(params_batch)
23
+ Base64.encode64(Marshal.dump(params_batch.parsed))
21
24
  end
22
25
 
23
- # @param params_batch [Hash] Sidekiqs params that are now a Hash (after they were JSON#parse)
24
- # @note Since Sidekiq does not like symbols, we restore symbolized keys for system keys, so
25
- # everything can work as expected. Keep in mind, that custom data will always be assigned
26
- # with string keys per design. To change it, please change this interchanger and create
27
- # your own custom parser
28
- def parse(params_batch)
29
- params_batch.map! do |params|
30
- Karafka::Params::Params::SYSTEM_KEYS.each do |key|
31
- stringified_key = key.to_s
32
- next unless params.key?(stringified_key)
33
- params[key] ||= params.delete(stringified_key)
34
- end
35
-
36
- params
37
- end
38
-
39
- params_batch
26
+ # @param params_batch [String] Encoded params batch string that we use to rebuild params
27
+ # @return [Karafka::Params::ParamsBatch] rebuilt params batch
28
+ def decode(params_batch)
29
+ Marshal.load(Base64.decode64(params_batch))
40
30
  end
41
31
  end
42
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-sidekiq-backend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.beta2
4
+ version: 1.2.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-16 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: karafka
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: 1.3.1
88
88
  requirements: []
89
89
  rubyforge_project:
90
- rubygems_version: 2.7.3
90
+ rubygems_version: 2.7.6
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Karafka Sidekiq backend for background messages processing