sidekiq-throttled 0.13.0 → 0.16.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +12 -16
  3. data/.rubocop.yml +14 -94
  4. data/.rubocop_todo.yml +42 -31
  5. data/Appraisals +14 -10
  6. data/CHANGES.md +65 -0
  7. data/Gemfile +7 -5
  8. data/LICENSE.md +2 -0
  9. data/README.md +42 -26
  10. data/Rakefile +1 -1
  11. data/gemfiles/sidekiq_6.0.gemfile +7 -5
  12. data/gemfiles/sidekiq_6.1.gemfile +7 -5
  13. data/gemfiles/{sidekiq_5.0.gemfile → sidekiq_6.2.gemfile} +8 -6
  14. data/gemfiles/{sidekiq_5.1.gemfile → sidekiq_6.3.gemfile} +8 -6
  15. data/gemfiles/{sidekiq_5.2.gemfile → sidekiq_6.4.gemfile} +8 -6
  16. data/gemfiles/sidekiq_6.5.gemfile +33 -0
  17. data/lib/sidekiq/throttled/communicator/callbacks.rb +8 -10
  18. data/lib/sidekiq/throttled/communicator/exception_handler.rb +25 -0
  19. data/lib/sidekiq/throttled/communicator/listener.rb +4 -4
  20. data/lib/sidekiq/throttled/communicator.rb +1 -1
  21. data/lib/sidekiq/throttled/expirable_list.rb +2 -5
  22. data/lib/sidekiq/throttled/fetch/unit_of_work.rb +7 -2
  23. data/lib/sidekiq/throttled/fetch.rb +5 -1
  24. data/lib/sidekiq/throttled/job.rb +128 -0
  25. data/lib/sidekiq/throttled/queue_name.rb +1 -1
  26. data/lib/sidekiq/throttled/registry.rb +0 -5
  27. data/lib/sidekiq/throttled/strategy.rb +15 -17
  28. data/lib/sidekiq/throttled/strategy_collection.rb +69 -0
  29. data/lib/sidekiq/throttled/utils.rb +1 -1
  30. data/lib/sidekiq/throttled/version.rb +1 -1
  31. data/lib/sidekiq/throttled/web/stats.rb +5 -4
  32. data/lib/sidekiq/throttled/web/summary_fix.rb +1 -1
  33. data/lib/sidekiq/throttled/web/throttled.html.erb +6 -2
  34. data/lib/sidekiq/throttled/web.rb +1 -1
  35. data/lib/sidekiq/throttled/worker.rb +6 -121
  36. data/lib/sidekiq/throttled.rb +5 -3
  37. data/rubocop/layout.yml +24 -0
  38. data/rubocop/lint.yml +41 -0
  39. data/rubocop/metrics.yml +4 -0
  40. data/rubocop/performance.yml +25 -0
  41. data/rubocop/rspec.yml +3 -0
  42. data/rubocop/style.yml +84 -0
  43. data/sidekiq-throttled.gemspec +8 -4
  44. metadata +27 -16
@@ -1,128 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # internal
4
- require "sidekiq/throttled/registry"
3
+ require "sidekiq/throttled/job"
5
4
 
6
5
  module Sidekiq
7
6
  module Throttled
8
- # Adds helpers to your worker classes
9
- #
10
- # @example Usage
11
- #
12
- # class MyWorker
13
- # include Sidekiq::Worker
14
- # include Sidekiq::Throttled::Worker
15
- #
16
- # sidkiq_options :queue => :my_queue
17
- # sidekiq_throttle :threshold => { :limit => 123, :period => 1.hour }
18
- #
19
- # def perform
20
- # # ...
21
- # end
22
- # end
23
- #
24
- # @see ClassMethods
25
- module Worker
26
- # Extends worker class with {ClassMethods}.
27
- #
28
- # @note Using `included` hook with extending worker with {ClassMethods}
29
- # in order to make API inline with `include Sidekiq::Worker`.
30
- #
31
- # @private
32
- def self.included(worker)
33
- worker.send(:extend, ClassMethods)
34
- end
35
-
36
- # Helper methods added to the singleton class of destination
37
- module ClassMethods
38
- # Registers some strategy for the worker.
39
- #
40
- # @example Allow max 123 MyWorker jobs per hour
41
- #
42
- # class MyWorker
43
- # include Sidekiq::Worker
44
- # include Sidekiq::Throttled::Worker
45
- #
46
- # sidekiq_throttle({
47
- # :threshold => { :limit => 123, :period => 1.hour }
48
- # })
49
- # end
50
- #
51
- # @example Allow max 10 concurrently running MyWorker jobs
52
- #
53
- # class MyWorker
54
- # include Sidekiq::Worker
55
- # include Sidekiq::Throttled::Worker
56
- #
57
- # sidekiq_throttle({
58
- # :concurrency => { :limit => 10 }
59
- # })
60
- # end
61
- #
62
- # @example Allow max 10 concurrent MyWorker jobs and max 123 per hour
63
- #
64
- # class MyWorker
65
- # include Sidekiq::Worker
66
- # include Sidekiq::Throttled::Worker
67
- #
68
- # sidekiq_throttle({
69
- # :threshold => { :limit => 123, :period => 1.hour },
70
- # :concurrency => { :limit => 10 }
71
- # })
72
- # end
73
- #
74
- # @see Registry.add
75
- # @return [void]
76
- def sidekiq_throttle(**kwargs)
77
- Registry.add(self, **kwargs)
78
- end
79
-
80
- # Adds current worker to preconfigured throtttling strtegy. Allows
81
- # sharing same pool for multiple workers.
82
- #
83
- # First of all we need to create shared throttling strategy:
84
- #
85
- # # Create google_api throttling strategy
86
- # Sidekiq::Throttled::Registry.add(:google_api, {
87
- # :threshold => { :limit => 123, :period => 1.hour },
88
- # :concurrency => { :limit => 123 }
89
- # })
90
- #
91
- # Now we can assign it to our workers:
92
- #
93
- # class FetchProfileJob
94
- # include Sidekiq::Worker
95
- # include Sidekiq::Throttled::Worker
96
- #
97
- # sidekiq_throttle_as :google_api
98
- # end
99
- #
100
- # class FetchCommentsJob
101
- # include Sidekiq::Worker
102
- # include Sidekiq::Throttled::Worker
103
- #
104
- # sidekiq_throttle_as :google_api
105
- # end
106
- #
107
- # With the above configuration we ensure that there are maximum 10
108
- # concurrently running jobs of FetchProfileJob or FetchCommentsJob
109
- # allowed. And only 123 jobs of those are executed per hour.
110
- #
111
- # In other words, it will allow:
112
- #
113
- # - only `X` concurrent `FetchProfileJob`s
114
- # - max `XX` `FetchProfileJob` per hour
115
- # - only `Y` concurrent `FetchCommentsJob`s
116
- # - max `YY` `FetchCommentsJob` per hour
117
- #
118
- # Where `(X + Y) == 10` and `(XX + YY) == 123`
119
- #
120
- # @see Registry.add_alias
121
- # @return [void]
122
- def sidekiq_throttle_as(name)
123
- Registry.add_alias(self, name)
124
- end
125
- end
126
- end
7
+ # A new module, Sidekiq::Job, was added in Sidekiq version 6.3.0 as a
8
+ # simple alias for Sidekiq::Worker as the term "worker" was considered
9
+ # too generic and confusing. Many people call a Sidekiq process a "worker"
10
+ # whereas others call the thread that executes jobs a "worker".
11
+ Worker = Job
127
12
  end
128
13
  end
@@ -9,6 +9,7 @@ require "sidekiq/throttled/communicator"
9
9
  require "sidekiq/throttled/configuration"
10
10
  require "sidekiq/throttled/queues_pauser"
11
11
  require "sidekiq/throttled/registry"
12
+ require "sidekiq/throttled/job"
12
13
  require "sidekiq/throttled/worker"
13
14
  require "sidekiq/throttled/utils"
14
15
 
@@ -74,10 +75,11 @@ module Sidekiq
74
75
  #
75
76
  # @param [String] message Job's JSON payload
76
77
  # @return [Boolean]
77
- def throttled?(message)
78
+ def throttled?(message) # rubocop:disable Metrics/MethodLength
78
79
  message = JSON.parse message
79
- job = message.fetch("class") { return false }
80
- jid = message.fetch("jid") { return false }
80
+ job = message.fetch("class") { return false }
81
+ job = message.fetch("wrapped") { return false } if job == "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
82
+ jid = message.fetch("jid") { return false }
81
83
 
82
84
  preload_constant! job
83
85
 
@@ -0,0 +1,24 @@
1
+ Layout/ArgumentAlignment:
2
+ EnforcedStyle: with_fixed_indentation
3
+
4
+ Layout/EmptyLinesAroundAttributeAccessor:
5
+ Enabled: true
6
+
7
+ Layout/FirstArrayElementIndentation:
8
+ EnforcedStyle: consistent
9
+
10
+ Layout/FirstHashElementIndentation:
11
+ Enabled: true
12
+ EnforcedStyle: consistent
13
+
14
+ Layout/HashAlignment:
15
+ Enabled: true
16
+ EnforcedHashRocketStyle: table
17
+ EnforcedColonStyle: table
18
+
19
+ Layout/SpaceAroundMethodCallOperator:
20
+ Enabled: true
21
+
22
+ Layout/MultilineMethodCallIndentation:
23
+ Enabled: true
24
+ EnforcedStyle: indented
data/rubocop/lint.yml ADDED
@@ -0,0 +1,41 @@
1
+ Lint/BinaryOperatorWithIdenticalOperands:
2
+ Enabled: true
3
+
4
+ Lint/DeprecatedOpenSSLConstant:
5
+ Enabled: true
6
+
7
+ Lint/DuplicateElsifCondition:
8
+ Enabled: true
9
+
10
+ Lint/DuplicateRescueException:
11
+ Enabled: true
12
+
13
+ Lint/EmptyConditionalBody:
14
+ Enabled: true
15
+
16
+ Lint/FloatComparison:
17
+ Enabled: true
18
+
19
+ Lint/MissingSuper:
20
+ Enabled: true
21
+
22
+ Lint/MixedRegexpCaptureTypes:
23
+ Enabled: true
24
+
25
+ Lint/OutOfRangeRegexpRef:
26
+ Enabled: true
27
+
28
+ Lint/RaiseException:
29
+ Enabled: true
30
+
31
+ Lint/SelfAssignment:
32
+ Enabled: true
33
+
34
+ Lint/StructNewOverride:
35
+ Enabled: true
36
+
37
+ Lint/TopLevelReturnWithArgument:
38
+ Enabled: true
39
+
40
+ Lint/UnreachableLoop:
41
+ Enabled: true
@@ -0,0 +1,4 @@
1
+ Metrics/BlockLength:
2
+ Exclude:
3
+ - "spec/**/*_spec.rb"
4
+ - "**/*.gemspec"
@@ -0,0 +1,25 @@
1
+ Performance/AncestorsInclude:
2
+ Enabled: true
3
+
4
+ Performance/BigDecimalWithNumericArgument:
5
+ Enabled: true
6
+
7
+ Performance/RedundantSortBlock:
8
+ Enabled: true
9
+
10
+ Performance/RedundantStringChars:
11
+ Enabled: true
12
+
13
+ Performance/ReverseFirst:
14
+ Enabled: true
15
+
16
+ Performance/SortReverse:
17
+ Enabled: true
18
+
19
+ Performance/Squeeze:
20
+ Enabled: true
21
+
22
+ Performance/StringInclude:
23
+ Enabled: true
24
+
25
+
data/rubocop/rspec.yml ADDED
@@ -0,0 +1,3 @@
1
+ RSpec/ExampleLength:
2
+ Enabled: true
3
+ Max: 15
data/rubocop/style.yml ADDED
@@ -0,0 +1,84 @@
1
+ Style/AccessorGrouping:
2
+ Enabled: true
3
+
4
+ Style/ArrayCoercion:
5
+ Enabled: true
6
+
7
+ Style/BisectedAttrAccessor:
8
+ Enabled: true
9
+
10
+ Style/CaseLikeIf:
11
+ Enabled: true
12
+
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ Style/ExplicitBlockArgument:
17
+ Enabled: true
18
+
19
+ Style/ExponentialNotation:
20
+ Enabled: true
21
+
22
+ Style/GlobalStdStream:
23
+ Enabled: true
24
+
25
+ Style/HashAsLastArrayItem:
26
+ Enabled: true
27
+
28
+ Style/HashEachMethods:
29
+ Enabled: true
30
+
31
+ Style/HashLikeCase:
32
+ Enabled: true
33
+
34
+ Style/HashSyntax:
35
+ Enabled: true
36
+ EnforcedStyle: hash_rockets
37
+
38
+ Style/HashTransformKeys:
39
+ Enabled: true
40
+
41
+ Style/HashTransformValues:
42
+ Enabled: true
43
+
44
+ Style/OptionalBooleanParameter:
45
+ Enabled: true
46
+
47
+ Style/RedundantAssignment:
48
+ Enabled: true
49
+
50
+ Style/RedundantFetchBlock:
51
+ Enabled: true
52
+
53
+ Style/RedundantFileExtensionInRequire:
54
+ Enabled: true
55
+
56
+ Style/RedundantRegexpCharacterClass:
57
+ Enabled: true
58
+
59
+ Style/RedundantRegexpEscape:
60
+ Enabled: true
61
+
62
+ Style/RegexpLiteral:
63
+ Enabled: true
64
+ EnforcedStyle: percent_r
65
+
66
+ Style/RescueStandardError:
67
+ Enabled: true
68
+ EnforcedStyle: implicit
69
+
70
+ Style/SingleArgumentDig:
71
+ Enabled: true
72
+
73
+ Style/SlicingWithRange:
74
+ Enabled: true
75
+
76
+ Style/StringConcatenation:
77
+ Enabled: true
78
+
79
+ Style/StringLiterals:
80
+ Enabled: true
81
+ EnforcedStyle: double_quotes
82
+
83
+ Style/YodaCondition:
84
+ Enabled: false
@@ -8,25 +8,29 @@ require "sidekiq/throttled/version"
8
8
  Gem::Specification.new do |spec|
9
9
  spec.name = "sidekiq-throttled"
10
10
  spec.version = Sidekiq::Throttled::VERSION
11
- spec.authors = ["Alexey V Zapparov"]
12
- spec.email = ["ixti@member.fsf.org"]
11
+ spec.authors = ["Alexey Zapparov"]
12
+ spec.email = ["alexey@zapparov.com"]
13
13
 
14
14
  spec.summary = "Concurrency and threshold throttling for Sidekiq."
15
15
  spec.description = "Concurrency and threshold throttling for Sidekiq."
16
- spec.homepage = "https://github.com/sensortower/sidekiq-throttled"
16
+ spec.homepage = "https://github.com/ixti/sidekiq-throttled"
17
17
  spec.license = "MIT"
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
20
  f.match %r{^(test|spec|features)/}
21
21
  end
22
22
 
23
+ spec.metadata["rubygems_mfa_required"] = "true"
24
+
23
25
  spec.bindir = "exe"
24
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
27
  spec.require_paths = ["lib"]
26
28
 
29
+ spec.required_ruby_version = ">= 2.7"
30
+
27
31
  spec.add_runtime_dependency "concurrent-ruby"
28
32
  spec.add_runtime_dependency "redis-prescription"
29
33
  spec.add_runtime_dependency "sidekiq"
30
34
 
31
- spec.add_development_dependency "bundler", "~> 2.0"
35
+ spec.add_development_dependency "bundler", ">= 2.0"
32
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-throttled
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
- - Alexey V Zapparov
8
- autorequire:
7
+ - Alexey Zapparov
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -56,19 +56,19 @@ dependencies:
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.0'
69
69
  description: Concurrency and threshold throttling for Sidekiq.
70
70
  email:
71
- - ixti@member.fsf.org
71
+ - alexey@zapparov.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
@@ -88,20 +88,23 @@ files:
88
88
  - LICENSE.md
89
89
  - README.md
90
90
  - Rakefile
91
- - gemfiles/sidekiq_5.0.gemfile
92
- - gemfiles/sidekiq_5.1.gemfile
93
- - gemfiles/sidekiq_5.2.gemfile
94
91
  - gemfiles/sidekiq_6.0.gemfile
95
92
  - gemfiles/sidekiq_6.1.gemfile
93
+ - gemfiles/sidekiq_6.2.gemfile
94
+ - gemfiles/sidekiq_6.3.gemfile
95
+ - gemfiles/sidekiq_6.4.gemfile
96
+ - gemfiles/sidekiq_6.5.gemfile
96
97
  - lib/sidekiq/throttled.rb
97
98
  - lib/sidekiq/throttled/communicator.rb
98
99
  - lib/sidekiq/throttled/communicator/callbacks.rb
100
+ - lib/sidekiq/throttled/communicator/exception_handler.rb
99
101
  - lib/sidekiq/throttled/communicator/listener.rb
100
102
  - lib/sidekiq/throttled/configuration.rb
101
103
  - lib/sidekiq/throttled/errors.rb
102
104
  - lib/sidekiq/throttled/expirable_list.rb
103
105
  - lib/sidekiq/throttled/fetch.rb
104
106
  - lib/sidekiq/throttled/fetch/unit_of_work.rb
107
+ - lib/sidekiq/throttled/job.rb
105
108
  - lib/sidekiq/throttled/middleware.rb
106
109
  - lib/sidekiq/throttled/patches/queue.rb
107
110
  - lib/sidekiq/throttled/queue_name.rb
@@ -113,6 +116,7 @@ files:
113
116
  - lib/sidekiq/throttled/strategy/concurrency.rb
114
117
  - lib/sidekiq/throttled/strategy/threshold.lua
115
118
  - lib/sidekiq/throttled/strategy/threshold.rb
119
+ - lib/sidekiq/throttled/strategy_collection.rb
116
120
  - lib/sidekiq/throttled/testing.rb
117
121
  - lib/sidekiq/throttled/utils.rb
118
122
  - lib/sidekiq/throttled/version.rb
@@ -123,12 +127,19 @@ files:
123
127
  - lib/sidekiq/throttled/web/summary_fix.rb
124
128
  - lib/sidekiq/throttled/web/throttled.html.erb
125
129
  - lib/sidekiq/throttled/worker.rb
130
+ - rubocop/layout.yml
131
+ - rubocop/lint.yml
132
+ - rubocop/metrics.yml
133
+ - rubocop/performance.yml
134
+ - rubocop/rspec.yml
135
+ - rubocop/style.yml
126
136
  - sidekiq-throttled.gemspec
127
- homepage: https://github.com/sensortower/sidekiq-throttled
137
+ homepage: https://github.com/ixti/sidekiq-throttled
128
138
  licenses:
129
139
  - MIT
130
- metadata: {}
131
- post_install_message:
140
+ metadata:
141
+ rubygems_mfa_required: 'true'
142
+ post_install_message:
132
143
  rdoc_options: []
133
144
  require_paths:
134
145
  - lib
@@ -136,15 +147,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
147
  requirements:
137
148
  - - ">="
138
149
  - !ruby/object:Gem::Version
139
- version: '0'
150
+ version: '2.7'
140
151
  required_rubygems_version: !ruby/object:Gem::Requirement
141
152
  requirements:
142
153
  - - ">="
143
154
  - !ruby/object:Gem::Version
144
155
  version: '0'
145
156
  requirements: []
146
- rubygems_version: 3.1.2
147
- signing_key:
157
+ rubygems_version: 3.1.6
158
+ signing_key:
148
159
  specification_version: 4
149
160
  summary: Concurrency and threshold throttling for Sidekiq.
150
161
  test_files: []