sidekiq-throttled 0.16.1 → 0.17.0

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
2
  SHA256:
3
- metadata.gz: 51d312add58d0286d72087cefbdd49eac85a07c5416034e731f5c755f9fe702a
4
- data.tar.gz: f7774ca65a0a26bb499dde8e34622d9e055b5112009228637a1f4b7696ad44bc
3
+ metadata.gz: 1a4884da942e03171d7265651258f4da2ca601aa36219192b325a2ce0ff113fd
4
+ data.tar.gz: 7b1d20e64db0cf3720f4b404a95744b77de186da718feb7f6abd7cd23623e08d
5
5
  SHA512:
6
- metadata.gz: 0e7170c5e6dbe4a5664523ab04794b2f921296c690fbac05e6a2966bc0285612374441ec86d561cf48a45d36369c8c2fe0154c99aa2b9ed347cec642a0c4d22a
7
- data.tar.gz: a7c8ff62bb1ff8e09f609f8d341ab57539e3db8aa8112c29d09f052b487310c5969e98c5e80c5cc6f1b4e1dbd13a278f7d117bb4ff13e28ee0e2f75743044b74
6
+ metadata.gz: 93699777efb1fd7794a7e566d6b129b0898f8efb327627b2a17b5e3e595a100fedc8b5a064ab8331b61c553cdd4a3aa2f3ac57c76d9d677c16ef006df18c592d
7
+ data.tar.gz: 9aaa27dbd6c116fbeac961cb8f8d1413bc1b9ff84241cfa81ce4b63b479a0b2386d6de8c94a6176a461d4f50867ce80957fd4b4569b5bd9db377d41fafbb247c
@@ -14,7 +14,7 @@ jobs:
14
14
  fail-fast: false
15
15
  matrix:
16
16
  ruby: [ "2.7", "3.0", "3.1" ]
17
- sidekiq: [ "6.0", "6.1", "6.2", "6.3", "6.4", "6.5" ]
17
+ sidekiq: [ "6.4", "6.5" ]
18
18
 
19
19
  runs-on: ubuntu-latest
20
20
 
data/.travis.yml CHANGED
@@ -33,7 +33,5 @@ matrix:
33
33
  gemfile: Gemfile
34
34
 
35
35
  gemfile:
36
- - gemfiles/sidekiq_5.0.gemfile
37
- - gemfiles/sidekiq_5.1.gemfile
38
- - gemfiles/sidekiq_5.2.gemfile
39
- - gemfiles/sidekiq_6.0.gemfile
36
+ - gemfiles/sidekiq_6.4.gemfile
37
+ - gemfiles/sidekiq_6.5.gemfile
data/Appraisals CHANGED
@@ -1,21 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise "sidekiq-6.0" do
4
- gem "sidekiq", "~> 6.0.0"
5
- end
6
-
7
- appraise "sidekiq-6.1" do
8
- gem "sidekiq", "~> 6.1.0"
9
- end
10
-
11
- appraise "sidekiq-6.2" do
12
- gem "sidekiq", "~> 6.2.0"
13
- end
14
-
15
- appraise "sidekiq-6.3" do
16
- gem "sidekiq", "~> 6.3.0"
17
- end
18
-
19
3
  appraise "sidekiq-6.4" do
20
4
  gem "sidekiq", "~> 6.4.0"
21
5
  end
data/README.md CHANGED
@@ -36,13 +36,13 @@ Sidekiq::Throttled.setup!
36
36
  Load order can be an issue if you are using other Sidekiq plugins and/or middleware.
37
37
  To prevent any problems, add the `.setup!` call to the bottom of your init file.
38
38
 
39
- Once you've done that you can include `Sidekiq::Throttled::Worker` to your
39
+ Once you've done that you can include `Sidekiq::Throttled::Job` to your
40
40
  job classes and configure throttling:
41
41
 
42
42
  ``` ruby
43
- class MyWorker
44
- include Sidekiq::Worker
45
- include Sidekiq::Throttled::Worker
43
+ class MyJob
44
+ include Sidekiq::Job
45
+ include Sidekiq::Throttled::Job
46
46
 
47
47
  sidekiq_options :queue => :my_queue
48
48
 
@@ -59,15 +59,29 @@ class MyWorker
59
59
  end
60
60
  ```
61
61
 
62
+ **NOTE:** `Sidekiq::Throttled::Job` is aliased as `Sidekiq::Throttled::Worker`,
63
+ thus if you're using Sidekiq prior 6.3.0 version, or you using `Sidekiq::Worker`
64
+ naming convention, you can use the alias for consistency:
65
+
66
+ ``` ruby
67
+ class MyWorker
68
+ include Sidekiq::Worker
69
+ include Sidekiq::Throttled::Worker
70
+
71
+ # ...
72
+ end
73
+ ```
74
+
75
+
62
76
  ### Observer
63
77
 
64
78
  You can specify an observer that will be called on throttling. To do so pass an
65
79
  `:observer` option with callable object:
66
80
 
67
81
  ``` ruby
68
- class MyWorker
69
- include Sidekiq::Worker
70
- include Sidekiq::Throttled::Worker
82
+ class MyJob
83
+ include Sidekiq::Job
84
+ include Sidekiq::Throttled::Job
71
85
 
72
86
  MY_OBSERVER = lambda do |strategy, *args|
73
87
  # do something
@@ -97,9 +111,9 @@ to the job.
97
111
  You can throttle jobs dynamically with `:key_suffix` option:
98
112
 
99
113
  ``` ruby
100
- class MyWorker
101
- include Sidekiq::Worker
102
- include Sidekiq::Throttled::Worker
114
+ class MyJob
115
+ include Sidekiq::Job
116
+ include Sidekiq::Throttled::Job
103
117
 
104
118
  sidekiq_options :queue => :my_queue
105
119
 
@@ -119,9 +133,9 @@ for these values. The proc will be evaluated at the time the job is fetched
119
133
  and will receive the same arguments that are passed to the job.
120
134
 
121
135
  ``` ruby
122
- class MyWorker
123
- include Sidekiq::Worker
124
- include Sidekiq::Throttled::Worker
136
+ class MyJob
137
+ include Sidekiq::Job
138
+ include Sidekiq::Throttled::Job
125
139
 
126
140
  sidekiq_options :queue => :my_queue
127
141
 
@@ -147,9 +161,9 @@ end
147
161
  You also can use several different keys to throttle one worker.
148
162
 
149
163
  ``` ruby
150
- class MyWorker
151
- include Sidekiq::Worker
152
- include Sidekiq::Throttled::Worker
164
+ class MyJob
165
+ include Sidekiq::Job
166
+ include Sidekiq::Throttled::Job
153
167
 
154
168
  sidekiq_options :queue => :my_queue
155
169
 
@@ -252,10 +266,6 @@ dropped.
252
266
 
253
267
  This library aims to support work with following [Sidekiq][sidekiq] versions:
254
268
 
255
- * Sidekiq 6.0.x
256
- * Sidekiq 6.1.x
257
- * Sidekiq 6.2.x
258
- * Sidekiq 6.3.x
259
269
  * Sidekiq 6.4.x
260
270
  * Sidekiq 6.5.x
261
271
 
@@ -21,14 +21,14 @@ module Sidekiq
21
21
  # Instructs throttler to lookup strategies in parent classes, if there's
22
22
  # no own strategy:
23
23
  #
24
- # class Foo
25
- # include Sidekiq::Worker
26
- # include Sidekiq::Worker::Throttled
24
+ # class FooJob
25
+ # include Sidekiq::Job
26
+ # include Sidekiq::Throttled::Job
27
27
  #
28
28
  # sidekiq_throttle :concurrency => { :limit => 42 }
29
29
  # end
30
30
  #
31
- # class Bar < Foo
31
+ # class BarJob < FooJob
32
32
  # end
33
33
  #
34
34
  # By default in the example above, `Bar` won't have throttling options.
@@ -12,33 +12,6 @@ module Sidekiq
12
12
  #
13
13
  # @private
14
14
  class Fetch
15
- module BulkRequeue
16
- # Requeues all given units as a single operation.
17
- #
18
- # @see http://www.rubydoc.info/github/redis/redis-rb/master/Redis#pipelined-instance_method
19
- # @param [Array<Fetch::UnitOfWork>] units
20
- # @return [void]
21
- def bulk_requeue(units, _options)
22
- return if units.empty?
23
-
24
- Sidekiq.logger.debug { "Re-queueing terminated jobs" }
25
- Sidekiq.redis do |conn|
26
- conn.pipelined do |pipeline|
27
- units.each { |unit| unit.requeue(pipeline) }
28
- end
29
- end
30
- Sidekiq.logger.info("Pushed #{units.size} jobs back to Redis")
31
- rescue => e
32
- Sidekiq.logger.warn("Failed to requeue #{units.size} jobs: #{e}")
33
- end
34
- end
35
-
36
- # https://github.com/mperham/sidekiq/commit/fce05c9d4b4c0411c982078a4cf3a63f20f739bc
37
- if Gem::Version.new(Sidekiq::VERSION) < Gem::Version.new("6.1.0")
38
- extend BulkRequeue
39
- else
40
- include BulkRequeue
41
- end
42
15
  # Timeout to sleep between fetch retries in case of no job received,
43
16
  # as well as timeout to wait for redis to give us something to work.
44
17
  TIMEOUT = 2
@@ -77,6 +50,20 @@ module Sidekiq
77
50
  nil
78
51
  end
79
52
 
53
+ def bulk_requeue(units, _options)
54
+ return if units.empty?
55
+
56
+ Sidekiq.logger.debug { "Re-queueing terminated jobs" }
57
+ Sidekiq.redis do |conn|
58
+ conn.pipelined do |pipeline|
59
+ units.each { |unit| unit.requeue(pipeline) }
60
+ end
61
+ end
62
+ Sidekiq.logger.info("Pushed #{units.size} jobs back to Redis")
63
+ rescue => e
64
+ Sidekiq.logger.warn("Failed to requeue #{units.size} jobs: #{e}")
65
+ end
66
+
80
67
  private
81
68
 
82
69
  # Tries to pop pair of `queue` and job `message` out of sidekiq queues.
@@ -91,7 +78,7 @@ module Sidekiq
91
78
  return
92
79
  end
93
80
 
94
- Sidekiq.redis { |conn| conn.brpop(*queues, TIMEOUT) }
81
+ Sidekiq.redis { |conn| conn.brpop(*queues, :timeout => TIMEOUT) }
95
82
  end
96
83
 
97
84
  # Returns list of queues to try to fetch jobs from.
@@ -9,9 +9,9 @@ module Sidekiq
9
9
  #
10
10
  # @example Usage
11
11
  #
12
- # class MyWorker
13
- # include Sidekiq::Worker
14
- # include Sidekiq::Throttled::Worker
12
+ # class MyJob
13
+ # include Sidekiq::Job
14
+ # include Sidekiq::Throttled::Job
15
15
  #
16
16
  # sidkiq_options :queue => :my_queue
17
17
  # sidekiq_throttle :threshold => { :limit => 123, :period => 1.hour }
@@ -26,7 +26,7 @@ module Sidekiq
26
26
  # Extends worker class with {ClassMethods}.
27
27
  #
28
28
  # @note Using `included` hook with extending worker with {ClassMethods}
29
- # in order to make API inline with `include Sidekiq::Worker`.
29
+ # in order to make API inline with `include Sidekiq::Job`.
30
30
  #
31
31
  # @private
32
32
  def self.included(worker)
@@ -37,33 +37,33 @@ module Sidekiq
37
37
  module ClassMethods
38
38
  # Registers some strategy for the worker.
39
39
  #
40
- # @example Allow max 123 MyWorker jobs per hour
40
+ # @example Allow max 123 MyJob jobs per hour
41
41
  #
42
- # class MyWorker
43
- # include Sidekiq::Worker
44
- # include Sidekiq::Throttled::Worker
42
+ # class MyJob
43
+ # include Sidekiq::Job
44
+ # include Sidekiq::Throttled::Job
45
45
  #
46
46
  # sidekiq_throttle({
47
47
  # :threshold => { :limit => 123, :period => 1.hour }
48
48
  # })
49
49
  # end
50
50
  #
51
- # @example Allow max 10 concurrently running MyWorker jobs
51
+ # @example Allow max 10 concurrently running MyJob jobs
52
52
  #
53
- # class MyWorker
54
- # include Sidekiq::Worker
55
- # include Sidekiq::Throttled::Worker
53
+ # class MyJob
54
+ # include Sidekiq::Job
55
+ # include Sidekiq::Throttled::Job
56
56
  #
57
57
  # sidekiq_throttle({
58
58
  # :concurrency => { :limit => 10 }
59
59
  # })
60
60
  # end
61
61
  #
62
- # @example Allow max 10 concurrent MyWorker jobs and max 123 per hour
62
+ # @example Allow max 10 concurrent MyJob jobs and max 123 per hour
63
63
  #
64
- # class MyWorker
65
- # include Sidekiq::Worker
66
- # include Sidekiq::Throttled::Worker
64
+ # class MyJob
65
+ # include Sidekiq::Job
66
+ # include Sidekiq::Throttled::Job
67
67
  #
68
68
  # sidekiq_throttle({
69
69
  # :threshold => { :limit => 123, :period => 1.hour },
@@ -91,15 +91,15 @@ module Sidekiq
91
91
  # Now we can assign it to our workers:
92
92
  #
93
93
  # class FetchProfileJob
94
- # include Sidekiq::Worker
95
- # include Sidekiq::Throttled::Worker
94
+ # include Sidekiq::Job
95
+ # include Sidekiq::Throttled::Job
96
96
  #
97
97
  # sidekiq_throttle_as :google_api
98
98
  # end
99
99
  #
100
100
  # class FetchCommentsJob
101
- # include Sidekiq::Worker
102
- # include Sidekiq::Throttled::Worker
101
+ # include Sidekiq::Job
102
+ # include Sidekiq::Throttled::Job
103
103
  #
104
104
  # sidekiq_throttle_as :google_api
105
105
  # end
@@ -3,6 +3,6 @@
3
3
  module Sidekiq
4
4
  module Throttled
5
5
  # Gem version
6
- VERSION = "0.16.1"
6
+ VERSION = "0.17.0"
7
7
  end
8
8
  end
@@ -22,12 +22,12 @@ module Sidekiq
22
22
  # require "sidekiq/throttled"
23
23
  # Sidekiq::Throttled.setup!
24
24
  #
25
- # Once you've done that you can include {Sidekiq::Throttled::Worker} to your
25
+ # Once you've done that you can include {Sidekiq::Throttled::Job} to your
26
26
  # job classes and configure throttling:
27
27
  #
28
- # class MyWorker
29
- # include Sidekiq::Worker
30
- # include Sidekiq::Throttled::Worker
28
+ # class MyJob
29
+ # include Sidekiq::Job
30
+ # include Sidekiq::Throttled::Job
31
31
  #
32
32
  # sidekiq_options :queue => :my_queue
33
33
  #
@@ -62,7 +62,7 @@ module Sidekiq
62
62
  QueuesPauser.instance.setup!
63
63
 
64
64
  Sidekiq.configure_server do |config|
65
- setup_strategy!
65
+ setup_strategy!(config)
66
66
 
67
67
  require "sidekiq/throttled/middleware"
68
68
  config.server_middleware do |chain|
@@ -94,16 +94,13 @@ module Sidekiq
94
94
  private
95
95
 
96
96
  # @return [void]
97
- def setup_strategy!
97
+ def setup_strategy!(sidekiq_config)
98
98
  require "sidekiq/throttled/fetch"
99
99
 
100
- # https://github.com/mperham/sidekiq/commit/fce05c9d4b4c0411c982078a4cf3a63f20f739bc
101
- Sidekiq.options[:fetch] =
102
- if Gem::Version.new(Sidekiq::VERSION) < Gem::Version.new("6.1.0")
103
- Sidekiq::Throttled::Fetch
104
- else
105
- Sidekiq::Throttled::Fetch.new(Sidekiq.options)
106
- end
100
+ # https://github.com/mperham/sidekiq/commit/67daa7a408b214d593100f782271ed108686c147
101
+ sidekiq_config = sidekiq_config.options if Gem::Version.new(Sidekiq::VERSION) < Gem::Version.new("6.5.0")
102
+
103
+ sidekiq_config[:fetch] = Sidekiq::Throttled::Fetch.new(sidekiq_config)
107
104
  end
108
105
 
109
106
  # Tries to preload constant by it's name once.
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_runtime_dependency "concurrent-ruby"
32
32
  spec.add_runtime_dependency "redis-prescription"
33
- spec.add_runtime_dependency "sidekiq"
33
+ spec.add_runtime_dependency "sidekiq", ">= 6.4"
34
34
 
35
35
  spec.add_development_dependency "bundler", ">= 2.0"
36
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.16.1
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Zapparov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-14 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '6.4'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '6.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -89,10 +89,6 @@ files:
89
89
  - LICENSE.md
90
90
  - README.md
91
91
  - Rakefile
92
- - gemfiles/sidekiq_6.0.gemfile
93
- - gemfiles/sidekiq_6.1.gemfile
94
- - gemfiles/sidekiq_6.2.gemfile
95
- - gemfiles/sidekiq_6.3.gemfile
96
92
  - gemfiles/sidekiq_6.4.gemfile
97
93
  - gemfiles/sidekiq_6.5.gemfile
98
94
  - lib/sidekiq/throttled.rb
@@ -155,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
151
  - !ruby/object:Gem::Version
156
152
  version: '0'
157
153
  requirements: []
158
- rubygems_version: 3.1.6
154
+ rubygems_version: 3.2.33
159
155
  signing_key:
160
156
  specification_version: 4
161
157
  summary: Concurrency and threshold throttling for Sidekiq.
@@ -1,33 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec"
8
- gem "sidekiq", "~> 6.0.0"
9
-
10
- group :development do
11
- gem "byebug"
12
- gem "guard", require: false
13
- gem "guard-rspec", require: false
14
- gem "guard-rubocop", require: false
15
- end
16
-
17
- group :test do
18
- gem "apparition"
19
- gem "capybara"
20
- gem "puma"
21
- gem "rack-test"
22
- gem "sinatra"
23
- gem "timecop"
24
- end
25
-
26
- group :lint do
27
- gem "rubocop", require: false
28
- gem "rubocop-performance", require: false
29
- gem "rubocop-rake", require: false
30
- gem "rubocop-rspec", require: false
31
- end
32
-
33
- gemspec path: "../"
@@ -1,33 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec"
8
- gem "sidekiq", "~> 6.1.0"
9
-
10
- group :development do
11
- gem "byebug"
12
- gem "guard", require: false
13
- gem "guard-rspec", require: false
14
- gem "guard-rubocop", require: false
15
- end
16
-
17
- group :test do
18
- gem "apparition"
19
- gem "capybara"
20
- gem "puma"
21
- gem "rack-test"
22
- gem "sinatra"
23
- gem "timecop"
24
- end
25
-
26
- group :lint do
27
- gem "rubocop", require: false
28
- gem "rubocop-performance", require: false
29
- gem "rubocop-rake", require: false
30
- gem "rubocop-rspec", require: false
31
- end
32
-
33
- gemspec path: "../"
@@ -1,33 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec"
8
- gem "sidekiq", "~> 6.2.0"
9
-
10
- group :development do
11
- gem "byebug"
12
- gem "guard", require: false
13
- gem "guard-rspec", require: false
14
- gem "guard-rubocop", require: false
15
- end
16
-
17
- group :test do
18
- gem "apparition"
19
- gem "capybara"
20
- gem "puma"
21
- gem "rack-test"
22
- gem "sinatra"
23
- gem "timecop"
24
- end
25
-
26
- group :lint do
27
- gem "rubocop", require: false
28
- gem "rubocop-performance", require: false
29
- gem "rubocop-rake", require: false
30
- gem "rubocop-rspec", require: false
31
- end
32
-
33
- gemspec path: "../"
@@ -1,33 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec"
8
- gem "sidekiq", "~> 6.3.0"
9
-
10
- group :development do
11
- gem "byebug"
12
- gem "guard", require: false
13
- gem "guard-rspec", require: false
14
- gem "guard-rubocop", require: false
15
- end
16
-
17
- group :test do
18
- gem "apparition"
19
- gem "capybara"
20
- gem "puma"
21
- gem "rack-test"
22
- gem "sinatra"
23
- gem "timecop"
24
- end
25
-
26
- group :lint do
27
- gem "rubocop", require: false
28
- gem "rubocop-performance", require: false
29
- gem "rubocop-rake", require: false
30
- gem "rubocop-rspec", require: false
31
- end
32
-
33
- gemspec path: "../"