karafka-sidekiq-backend 1.1.0 → 1.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 553a28cdeb2098d283624a91466b7818d9714e72
4
- data.tar.gz: c5ff002048db97b873050bcaf536b3a060106f7e
2
+ SHA256:
3
+ metadata.gz: 16558b17b692066dafda116ac5305f97eb090223c525ef9f7d928421ff035778
4
+ data.tar.gz: 47a3e0b1dcc3553077c2144f2e175318ac1de7a2bff40f33501c54361bf369b6
5
5
  SHA512:
6
- metadata.gz: 2aebcdd89c8584069f08f1e40940e92f2f431c97498612a1e28a08f8a1ef71b88451b60fdc1c6912829766fb18e89650560c5bc2c8c0bbd89def76a2a8f94b62
7
- data.tar.gz: 181d1cfbd38631224bd2ece579e1bd149d6b3d0cc5dc52e5b6bd39f0cfbdcc8637fc6f4a902c4a4bb7b4f49c4b76512bdcdb4eae6940fef98db5bbe336bccbed
6
+ metadata.gz: 43ea83d99f762fa1d9d709773959fd5c94cba803be58f4f32d19fd1bf080c4ec25d195c72bc874a947af9b4220ea91bfee47e890d229319d8f7607e1da30e0fe
7
+ data.tar.gz: 74b9743f1df06af45ca2953e055bd3622693b326ce347f1bf887d8a299c59a1b8c3c3cedbaefb7b76453aee0f788571717a85484934d5cab2578ec0355906310
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.2
1
+ 2.5.0
data/.travis.yml CHANGED
@@ -9,6 +9,7 @@ rvm:
9
9
  - 2.4.0
10
10
  - 2.4.1
11
11
  - 2.4.2
12
+ - 2.5.0
12
13
  - jruby-head
13
14
  script: bundle exec rspec spec/
14
15
  env:
data/CHANGELOG.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # Karafka Sidekiq Backend
2
2
 
3
+ ## 1.2.0.beta1
4
+ - #274 - Rename controllers to consumers
5
+ - Karafka 1.2 support
6
+
3
7
  ## 1.1
4
8
  - Ruby 2.4.2 support
5
9
  - #235 - Rename perform to consume
6
10
  - Karafka 1.1 support
11
+ - Ruby 2.5.0 support
7
12
 
8
13
  ## 1.0
9
14
 
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :development, :test do
8
- gem 'timecop'
9
8
  gem 'rspec'
10
9
  gem 'simplecov'
10
+ gem 'timecop'
11
11
  end
data/Gemfile.lock CHANGED
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-sidekiq-backend (1.1.0)
5
- karafka (>= 1.1.0.alpha2)
4
+ karafka-sidekiq-backend (1.2.0.beta1)
5
+ karafka (>= 1.2.0.beta1)
6
6
  sidekiq (>= 4.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (5.1.4)
11
+ activesupport (5.1.5)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (~> 0.7)
14
14
  minitest (~> 5.1)
15
15
  tzinfo (~> 1.1)
16
16
  concurrent-ruby (1.0.5)
17
17
  connection_pool (2.2.1)
18
- delivery_boy (0.2.2)
18
+ delivery_boy (0.2.4)
19
19
  king_konf (~> 0.1.8)
20
- ruby-kafka (~> 0.4)
20
+ ruby-kafka (~> 0.5.1)
21
21
  diff-lcs (1.3)
22
22
  docile (1.1.5)
23
23
  dry-configurable (0.7.0)
@@ -25,14 +25,24 @@ GEM
25
25
  dry-container (0.6.0)
26
26
  concurrent-ruby (~> 1.0)
27
27
  dry-configurable (~> 0.1, >= 0.1.3)
28
- dry-core (0.4.0)
28
+ dry-core (0.4.4)
29
29
  concurrent-ruby (~> 1.0)
30
30
  dry-equalizer (0.2.0)
31
+ dry-events (0.1.0)
32
+ concurrent-ruby (~> 1.0)
33
+ dry-core (~> 0.4)
34
+ dry-equalizer (~> 0.2)
35
+ dry-inflector (0.1.1)
31
36
  dry-logic (0.4.2)
32
37
  dry-container (~> 0.2, >= 0.2.6)
33
38
  dry-core (~> 0.2)
34
39
  dry-equalizer (~> 0.2)
35
- dry-types (0.12.1)
40
+ dry-monitor (0.1.2)
41
+ dry-configurable (~> 0.5)
42
+ dry-equalizer (~> 0.2)
43
+ dry-events (~> 0.1)
44
+ rouge (~> 2.0, >= 2.2.1)
45
+ dry-types (0.12.2)
36
46
  concurrent-ruby (~> 1.0)
37
47
  dry-configurable (~> 0.1)
38
48
  dry-container (~> 0.3)
@@ -49,36 +59,39 @@ GEM
49
59
  dry-types (~> 0.12.0)
50
60
  envlogic (1.0.4)
51
61
  activesupport
52
- i18n (0.9.1)
62
+ i18n (0.9.5)
53
63
  concurrent-ruby (~> 1.0)
54
64
  inflecto (0.0.2)
55
65
  json (2.1.0)
56
- karafka (1.1.0.alpha2)
57
- activesupport (>= 5.0)
66
+ karafka (1.2.0.beta1)
67
+ activesupport (>= 4.0)
58
68
  dry-configurable (~> 0.7)
69
+ dry-inflector (~> 0.1.1)
70
+ dry-monitor (~> 0.1)
59
71
  dry-validation (~> 0.11)
60
72
  envlogic (~> 1.0)
61
73
  multi_json (>= 1.12)
62
74
  rake (>= 11.3)
63
75
  require_all (>= 1.4)
64
- ruby-kafka (>= 0.5)
76
+ ruby-kafka (>= 0.5.3)
65
77
  thor (~> 0.19)
66
- waterdrop (>= 1.0.alpha2)
67
- king_konf (0.1.8)
68
- minitest (5.10.3)
69
- multi_json (1.12.2)
78
+ waterdrop (>= 1.2.0.beta1)
79
+ king_konf (0.1.10)
80
+ minitest (5.11.3)
81
+ multi_json (1.13.1)
70
82
  null-logger (0.1.4)
71
- rack (2.0.3)
83
+ rack (2.0.4)
72
84
  rack-protection (2.0.0)
73
85
  rack
74
- rake (12.2.1)
86
+ rake (12.3.0)
75
87
  redis (4.0.1)
76
- require_all (1.4.0)
88
+ require_all (1.5.0)
89
+ rouge (2.2.1)
77
90
  rspec (3.7.0)
78
91
  rspec-core (~> 3.7.0)
79
92
  rspec-expectations (~> 3.7.0)
80
93
  rspec-mocks (~> 3.7.0)
81
- rspec-core (3.7.0)
94
+ rspec-core (3.7.1)
82
95
  rspec-support (~> 3.7.0)
83
96
  rspec-expectations (3.7.0)
84
97
  diff-lcs (>= 1.2.0, < 2.0)
@@ -86,13 +99,13 @@ GEM
86
99
  rspec-mocks (3.7.0)
87
100
  diff-lcs (>= 1.2.0, < 2.0)
88
101
  rspec-support (~> 3.7.0)
89
- rspec-support (3.7.0)
90
- ruby-kafka (0.5.0)
91
- sidekiq (5.0.5)
102
+ rspec-support (3.7.1)
103
+ ruby-kafka (0.5.3)
104
+ sidekiq (5.1.1)
92
105
  concurrent-ruby (~> 1.0)
93
106
  connection_pool (~> 2.2, >= 2.2.0)
94
107
  rack-protection (>= 1.5.0)
95
- redis (>= 3.3.4, < 5)
108
+ redis (>= 3.3.5, < 5)
96
109
  simplecov (0.15.1)
97
110
  docile (~> 1.1.0)
98
111
  json (>= 1.8, < 3)
@@ -101,14 +114,15 @@ GEM
101
114
  thor (0.20.0)
102
115
  thread_safe (0.3.6)
103
116
  timecop (0.9.1)
104
- tzinfo (1.2.4)
117
+ tzinfo (1.2.5)
105
118
  thread_safe (~> 0.1)
106
- waterdrop (1.0.0)
107
- delivery_boy (>= 0.2.2)
119
+ waterdrop (1.2.0.beta1)
120
+ delivery_boy (>= 0.2.3)
108
121
  dry-configurable (~> 0.7)
122
+ dry-monitor (~> 0.1)
109
123
  dry-validation (~> 0.11)
110
124
  null-logger
111
- ruby-kafka (>= 0.5)
125
+ ruby-kafka (>= 0.5.3)
112
126
 
113
127
  PLATFORMS
114
128
  ruby
@@ -120,4 +134,4 @@ DEPENDENCIES
120
134
  timecop
121
135
 
122
136
  BUNDLED WITH
123
- 1.15.4
137
+ 1.16.1
data/README.md CHANGED
@@ -120,23 +120,14 @@ end
120
120
  * [Karafka Sidekiq Backend Travis CI](https://travis-ci.org/karafka/karafka-sidekiq-backend)
121
121
  * [Karafka Sidekiq Backend Coditsu](https://app.coditsu.io/karafka/repositories/karafka-sidekiq-backend)
122
122
 
123
- ## Note on Patches/Pull Requests
123
+ ## Note on contributions
124
124
 
125
- Fork the project.
126
- Make your feature addition or bug fix.
127
- Add tests for it. This is important so we don't break it in a future versions unintentionally.
128
- Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull). Send me a pull request. Bonus points for topic branches.
125
+ First, thank you for considering contributing to Karafka! It's people like you that make the open source community such a great community!
129
126
 
130
- [![coditsu](https://coditsu.io/assets/quality_bar.svg)](https://app.coditsu.io/karafka/repositories/karafka-sidekiq-backend)
127
+ Each pull request must pass all the rspec specs and meet our quality requirements.
131
128
 
132
- Each pull request must pass our quality requirements. To check if everything is as it should be, we use [Coditsu](https://coditsu.io) that combinse multiple linters and code analyzers for both code and documentation.
129
+ To check if everything is as it should be, we use [Coditsu](https://coditsu.io) that combines multiple linters and code analyzers for both code and documentation. Once you're done with your changes, submit a pull request.
133
130
 
134
- Unfortunately, it does not yet support independent forks, however you should be fine by looking at what we require.
131
+ Coditsu will automatically check your work against our quality standards. You can find your commit check results on the [builds page](https://app.coditsu.io/karafka/repositories/karafka-sidekiq-backend/builds/commit_builds) of Karafka Sidekiq Backend repository.
135
132
 
136
- Please run:
137
-
138
- ```bash
139
- bundle exec rake
140
- ```
141
-
142
- to check if everything is in order. After that you can submit a pull request.
133
+ [![coditsu](https://coditsu.io/assets/quality_bar.svg)](https://app.coditsu.io/karafka/repositories/karafka-sidekiq-backend/builds/commit_builds)
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.description = 'Karafka Sidekiq backend for background messages processing'
16
16
  spec.license = 'MIT'
17
17
 
18
- spec.add_dependency 'karafka', '>= 1.1.0.alpha2'
18
+ spec.add_dependency 'karafka', '>= 1.2.0.beta1'
19
19
  spec.add_dependency 'sidekiq', '>= 4.2'
20
20
  spec.required_ruby_version = '>= 2.3.0'
21
21
 
@@ -5,21 +5,20 @@ 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.1.0'
9
-
10
- private
8
+ VERSION = '1.2.0.beta1'
11
9
 
12
10
  # Enqueues the execution of perform method into a worker.
13
11
  # @note Each worker needs to have a class #perform_async method that will allow us to pass
14
12
  # parameters into it. We always pass topic as a first argument and this request
15
- # params_batch as a second one (we pass topic to be able to build back the controller
13
+ # params_batch as a second one (we pass topic to be able to build back the consumer
16
14
  # in the worker)
17
- def process
18
- Karafka.monitor.notice(self.class, params_batch)
19
- topic.worker.perform_async(
20
- topic.id,
21
- topic.interchanger.load(params_batch.to_a)
22
- )
15
+ def call
16
+ Karafka.monitor.instrument('backends.sidekiq.process', caller: self) do
17
+ topic.worker.perform_async(
18
+ topic.id,
19
+ topic.interchanger.load(params_batch.to_a)
20
+ )
21
+ end
23
22
  end
24
23
  end
25
24
  end
@@ -5,23 +5,28 @@ module Karafka
5
5
  class BaseWorker
6
6
  include Sidekiq::Worker
7
7
 
8
- # Executes the logic that lies in #perform Karafka controller method
8
+ # Executes the logic that lies in #perform Karafka consumer method
9
9
  # @param topic_id [String] Unique topic id that we will use to find a proper topic
10
10
  # @param params_batch [Array] Array with messages batch
11
11
  def perform(topic_id, params_batch)
12
- Karafka.monitor.notice(self.class, params_batch)
13
- controller(topic_id, params_batch).consume
12
+ consumer = consumer(topic_id, params_batch)
13
+
14
+ Karafka.monitor.instrument(
15
+ 'backends.sidekiq.base_worker.perform',
16
+ caller: self,
17
+ consumer: consumer
18
+ ) { consumer.consume }
14
19
  end
15
20
 
16
21
  private
17
22
 
18
- # @return [Karafka::Controller] descendant of Karafka::BaseController that matches the topic
19
- # with params_batch assigned already (controller is ready to use)
20
- def controller(topic_id, params_batch)
23
+ # @return [Karafka::Consumer] descendant of Karafka::BaseConsumer that matches the topic
24
+ # with params_batch assigned already (consumer is ready to use)
25
+ def consumer(topic_id, params_batch)
21
26
  topic = Karafka::Routing::Router.find(topic_id)
22
- controller = topic.controller.new
23
- controller.params_batch = topic.interchanger.parse(params_batch)
24
- controller
27
+ consumer = topic.consumer.new
28
+ consumer.params_batch = topic.interchanger.parse(params_batch)
29
+ consumer
25
30
  end
26
31
  end
27
32
  end
@@ -8,9 +8,9 @@ module Karafka
8
8
  module SidekiqTopicAttributes
9
9
  # @return [Class] Class (not an instance) of a worker that should be used to schedule the
10
10
  # background job
11
- # @note If not provided - will be built based on the provided controller
11
+ # @note If not provided - will be built based on the provided consumer
12
12
  def worker
13
- @worker ||= backend == :sidekiq ? Karafka::Workers::Builder.new(controller).build : nil
13
+ @worker ||= backend == :sidekiq ? Karafka::Workers::Builder.new(consumer).build : nil
14
14
  end
15
15
 
16
16
  # @return [Class] Interchanger class (not an instance) that we want to use to interchange
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ # Namespace for extensions of Karafka core framework instrumentation
5
+ module Instrumentation
6
+ # Additional methods for listener that listen on instrumentation related to the Sidekiq
7
+ # backend of Karafka
8
+ module Listener
9
+ class << self
10
+ # Logs info about scheduling of a certain dataset with a Sidekiq backend
11
+ # @param event [Dry::Events::Event] event details including payload
12
+ def on_backends_sidekiq_process(event)
13
+ count = event[:caller].send(:params_batch).to_a.size
14
+ topic = event[:caller].topic.name
15
+ time = event[:time]
16
+ info "Scheduling of #{count} messages to Sidekiq on topic #{topic} took #{time} ms"
17
+ end
18
+
19
+ # Logs ino about processing certain events with a given Sidekiq worker
20
+ # @param event [Dry::Events::Event] event details including payload
21
+ def on_backends_sidekiq_base_worker_perform(event)
22
+ count = event[:consumer].send(:params_batch).to_a.size
23
+ topic = event[:consumer].topic.name
24
+ time = event[:time]
25
+ info "Sidekiq processing of topic #{topic} with #{count} messages took #{time} ms"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -20,12 +20,20 @@ module Karafka
20
20
  end
21
21
 
22
22
  # @param params_batch [Hash] Sidekiqs params that are now a Hash (after they were JSON#parse)
23
- # @note Hash is what we need to build Karafka::Params::Params, so we do nothing
24
- # with it. If you implement your own interchanger logic, this method needs to return
25
- # a hash with appropriate data that will be used to build Karafka::Params::Params
26
- # @return [Hash] We return exactly what we received. We rely on sidekiqs default
27
- # interchanging format
23
+ # @note Since Sidekiq does not like symbols, we restore symbolized keys for system keys, so
24
+ # everything can work as expected. Keep in mind, that custom data will always be assigned
25
+ # with string keys per design. To change it, pleasae change this interchanger and create
26
+ # your own custom parser
28
27
  def parse(params_batch)
28
+ params_batch.map! do |params|
29
+ Karafka::Params::Params::SYSTEM_KEYS.each do |key|
30
+ stringified_key = key.to_s
31
+ params[key] = params.delete(stringified_key) if params.key?(stringified_key)
32
+ end
33
+
34
+ params
35
+ end
36
+
29
37
  params_batch
30
38
  end
31
39
  end
@@ -3,23 +3,23 @@
3
3
  module Karafka
4
4
  # Internal stuff related to workers
5
5
  module Workers
6
- # Builder is used to check if there is a proper controller with the same name as
7
- # a controller and if not, it will create a default one using Karafka::BaseWorker
8
- # This is used as a building layer between controllers and workers. it will be only used
9
- # when user does not provide his own worker that should perform controller stuff
6
+ # Builder is used to check if there is a proper consumer with the same name as
7
+ # a consumer and if not, it will create a default one using Karafka::BaseWorker
8
+ # This is used as a building layer between consumers and workers. it will be only used
9
+ # when user does not provide his own worker that should perform consumer stuff
10
10
  class Builder
11
- # @param controller_class [Karafka::BaseController] descendant of Karafka::BaseController
11
+ # @param consumer_class [Karafka::BaseConsumer] descendant of Karafka::BaseConsumer
12
12
  # @example Create a worker builder
13
- # Karafka::Workers::Builder.new(SuperController)
14
- def initialize(controller_class)
15
- @controller_class = controller_class
13
+ # Karafka::Workers::Builder.new(SuperConsumer)
14
+ def initialize(consumer_class)
15
+ @consumer_class = consumer_class
16
16
  end
17
17
 
18
18
  # @return [Class] Sidekiq worker class that already exists or new build based
19
- # on the provided controller_class name
20
- # @example Controller: SuperController
19
+ # on the provided consumer_class name
20
+ # @example Consumer: SuperConsumer
21
21
  # build #=> SuperWorker
22
- # @example Controller: Videos::NewVideosController
22
+ # @example Consumer: Videos::NewVideosConsumer
23
23
  # build #=> Videos::NewVideosWorker
24
24
  def build
25
25
  return matcher.match if matcher.match
@@ -37,12 +37,12 @@ module Karafka
37
37
  Karafka::BaseWorker.subclasses.first || raise(Errors::BaseWorkerDescentantMissing)
38
38
  end
39
39
 
40
- # @return [Karafka::Helpers::ClassMatcher] matcher instance for matching between controller
40
+ # @return [Karafka::Helpers::ClassMatcher] matcher instance for matching between consumer
41
41
  # and appropriate worker
42
42
  def matcher
43
43
  @matcher ||= Helpers::ClassMatcher.new(
44
- @controller_class,
45
- from: 'Controller',
44
+ @consumer_class,
45
+ from: 'Consumer',
46
46
  to: 'Worker'
47
47
  )
48
48
  end
@@ -27,3 +27,8 @@ end
27
27
  # Uses Karafka loader to load all the sources that this backend needs
28
28
  Karafka::Loader.load!(Karafka::Backends::Sidekiq.core_root)
29
29
  Karafka::AttributesMap.prepend(Karafka::Extensions::SidekiqAttributesMap)
30
+ # Register internal events for instrumentation
31
+ %w[
32
+ backends.sidekiq.process
33
+ backends.sidekiq.base_worker.perform
34
+ ].each(&Karafka.monitor.method(:register_event))
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.1.0
4
+ version: 1.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: karafka
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.0.alpha2
19
+ version: 1.2.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.1.0.alpha2
26
+ version: 1.2.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sidekiq
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -64,6 +64,7 @@ files:
64
64
  - lib/karafka/errors.rb
65
65
  - lib/karafka/extensions/sidekiq_attributes_map.rb
66
66
  - lib/karafka/extensions/sidekiq_topic_attributes.rb
67
+ - lib/karafka/instrumentation/listener.rb
67
68
  - lib/karafka/interchanger.rb
68
69
  - lib/karafka/workers/builder.rb
69
70
  homepage: https://github.com/karafka/karafka-sidekiq-backend
@@ -81,12 +82,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
82
  version: 2.3.0
82
83
  required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  requirements:
84
- - - ">="
85
+ - - ">"
85
86
  - !ruby/object:Gem::Version
86
- version: '0'
87
+ version: 1.3.1
87
88
  requirements: []
88
89
  rubyforge_project:
89
- rubygems_version: 2.6.13
90
+ rubygems_version: 2.7.3
90
91
  signing_key:
91
92
  specification_version: 4
92
93
  summary: Karafka Sidekiq backend for background messages processing