sidekiq-throttled 1.2.0 → 1.3.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: 6a187d7a0ab7f55794f909da549082fb32ec06acca0e75928fa970fd2312a63e
4
- data.tar.gz: c6acd8c1ebe40741e0285e6de82c0384b60a7a03ccee602b8de29309cb8bc313
3
+ metadata.gz: 433460cfaea479faf45edc665c6f8d7d025b3e35ccdf18a32061a0b3d3c42e68
4
+ data.tar.gz: 4e36f4c938d7145646e04f1de6d483bdec5a4c18254c3153be3556285b779fbf
5
5
  SHA512:
6
- metadata.gz: 6f777dff16dc389b43a089c4e392228afc695830bea0bedb4a4aa4b04d49b44a0ae5b60d643a255548947f90eeb198aaf91219f9f282de29b8c7c009626e6e4f
7
- data.tar.gz: 86b28f4fa073f7930254269e766576da4bf3412a262d9e0329285221b1376437dc6f072e9aa93be1402da7e06f3f5501ce416b241d134c666546ae3abb7397fe
6
+ metadata.gz: 3ba640f6b15fa32eb21eccda8a319357439b7367fea6c0e4d4125e0e2cd5e91fbb822768d2171c57ac0cfbe0ba640b1d21960c6e2ea317997869c8f06187aec9
7
+ data.tar.gz: bd28f31c6222b3f378e1e7a2d081cc9f05c4feb13b7be8b1b54ee91976a66b2263884837f3149dddcc6b047129a0311b65135433511b0dc3ed29d47ed88346ea
data/README.adoc CHANGED
@@ -107,7 +107,7 @@ end
107
107
  * `Sidekiq::Throttled::Middlewares::Server`
108
108
 
109
109
  The middleware is automatically injected when you require `sidekiq/throttled`.
110
- In rare cases this might be an issue. You can change to order manually:
110
+ In rare cases, when this causes an issue, you can change middleware order manually:
111
111
 
112
112
  [source,ruby]
113
113
  ----
@@ -115,8 +115,7 @@ Sidekiq.configure_server do |config|
115
115
  # ...
116
116
 
117
117
  config.server_middleware do |chain|
118
- chain.remove(Sidekiq::Throttled::Middlewares::Server)
119
- chain.add(Sidekiq::Throttled::Middlewares::Server)
118
+ chain.prepend(Sidekiq::Throttled::Middlewares::Server)
120
119
  end
121
120
  end
122
121
  ----
@@ -271,6 +270,7 @@ This library aims to support and is tested against the following Ruby versions:
271
270
  * Ruby 3.0.x
272
271
  * Ruby 3.1.x
273
272
  * Ruby 3.2.x
273
+ * Ruby 3.3.x
274
274
 
275
275
  If something doesn't work on one of these versions, it's a bug.
276
276
 
@@ -295,6 +295,11 @@ This library aims to support and work with following Sidekiq versions:
295
295
  * Sidekiq 7.1.x
296
296
  * Sidekiq 7.2.x
297
297
 
298
+ And the following Sidekiq Pro versions:
299
+
300
+ * Sidekiq Pro 7.0.x
301
+ * Sidekiq Pro 7.1.x
302
+ * Sidekiq Pro 7.2.x
298
303
 
299
304
  == Development
300
305
 
@@ -303,6 +308,11 @@ This library aims to support and work with following Sidekiq versions:
303
308
  bundle exec appraisal install
304
309
  bundle exec rake
305
310
 
311
+ === Sidekiq-Pro
312
+
313
+ If you're working on Sidekiq-Pro support make sure to copy `.rspec-sidekiq-pro`
314
+ to `.rspec-local` and that you have Sidekiq-Pro license in the global config,
315
+ or in the `BUNDLE_GEMS\__CONTRIBSYS__COM` env variable.
306
316
 
307
317
  == Contributing
308
318
 
@@ -3,25 +3,14 @@
3
3
  require "sidekiq"
4
4
  require "sidekiq/fetch"
5
5
 
6
+ require_relative "./throttled_retriever"
7
+
6
8
  module Sidekiq
7
9
  module Throttled
8
10
  module Patches
9
11
  module BasicFetch
10
- # Retrieves job from redis.
11
- #
12
- # @return [Sidekiq::Throttled::UnitOfWork, nil]
13
- def retrieve_work
14
- work = super
15
-
16
- if work && Throttled.throttled?(work.job)
17
- Throttled.cooldown&.notify_throttled(work.queue)
18
- requeue_throttled(work)
19
- return nil
20
- end
21
-
22
- Throttled.cooldown&.notify_admitted(work.queue) if work
23
-
24
- work
12
+ def self.prepended(base)
13
+ base.prepend(ThrottledRetriever)
25
14
  end
26
15
 
27
16
  private
@@ -43,7 +32,10 @@ module Sidekiq
43
32
  # @param [Array<String>] queues
44
33
  # @return [Array<String>]
45
34
  def queues_cmd
46
- super - (Throttled.cooldown&.queues || [])
35
+ throttled_queues = Throttled.cooldown&.queues
36
+ return super if throttled_queues.nil? || throttled_queues.empty?
37
+
38
+ super - throttled_queues
47
39
  end
48
40
  end
49
41
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq"
4
+
5
+ require_relative "./throttled_retriever"
6
+
7
+ module Sidekiq
8
+ module Throttled
9
+ module Patches
10
+ module SuperFetch
11
+ def self.prepended(base)
12
+ base.prepend(ThrottledRetriever)
13
+ end
14
+
15
+ private
16
+
17
+ # Calls SuperFetch UnitOfWork's requeue to remove the job from the
18
+ # temporary queue and push job back to the head of the queue, so that
19
+ # the job won't be tried immediately after it was requeued (in most cases).
20
+ #
21
+ # @note This is triggered when job is throttled.
22
+ #
23
+ # @return [void]
24
+ def requeue_throttled(work)
25
+ # SuperFetch UnitOfWork's requeue will remove it from the temporary
26
+ # queue and then requeue it, so no acknowledgement call is needed.
27
+ work.requeue
28
+ end
29
+
30
+ # Returns list of non-paused queues to try to fetch jobs from.
31
+ #
32
+ # @note It may return an empty array.
33
+ # @return [Array<Array(String, String)>]
34
+ def active_queues
35
+ # Create a hash of throttled queues for fast lookup
36
+ throttled_queues = Throttled.cooldown&.queues&.to_h { |queue| [queue, true] }
37
+ return super if throttled_queues.nil? || throttled_queues.empty?
38
+
39
+ # Reject throttled queues from the list of active queues
40
+ super.reject { |queue, _private_queue| throttled_queues[queue] }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ begin
48
+ require "sidekiq/pro/super_fetch"
49
+ Sidekiq::Pro::SuperFetch.prepend(Sidekiq::Throttled::Patches::SuperFetch)
50
+ rescue LoadError
51
+ # Sidekiq Pro is not available
52
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sidekiq
4
+ module Throttled
5
+ module Patches
6
+ module ThrottledRetriever
7
+ # Retrieves job from redis.
8
+ #
9
+ # @return [Sidekiq::BasicFetch::UnitOfWork, nil]
10
+ def retrieve_work
11
+ work = super
12
+
13
+ if work && Throttled.throttled?(work.job)
14
+ Throttled.cooldown&.notify_throttled(work.queue)
15
+ requeue_throttled(work)
16
+ return nil
17
+ end
18
+
19
+ Throttled.cooldown&.notify_admitted(work.queue) if work
20
+
21
+ work
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -26,8 +26,8 @@ module Sidekiq
26
26
 
27
27
  # @param [#call] block
28
28
  # Iterates each strategy in collection
29
- def each(&block)
30
- @strategies.each(&block)
29
+ def each(...)
30
+ @strategies.each(...)
31
31
  end
32
32
 
33
33
  # @return [Boolean] whenever any strategy in collection has dynamic config
@@ -37,14 +37,14 @@ module Sidekiq
37
37
 
38
38
  # @return [Boolean] whenever job is throttled or not
39
39
  # by any strategy in collection.
40
- def throttled?(*args)
41
- any? { |s| s.throttled?(*args) }
40
+ def throttled?(...)
41
+ any? { |s| s.throttled?(...) }
42
42
  end
43
43
 
44
44
  # Marks job as being processed.
45
45
  # @return [void]
46
- def finalize!(*args)
47
- each { |c| c.finalize!(*args) }
46
+ def finalize!(...)
47
+ each { |c| c.finalize!(...) }
48
48
  end
49
49
 
50
50
  # Resets count of jobs of all avaliable strategies
@@ -3,6 +3,6 @@
3
3
  module Sidekiq
4
4
  module Throttled
5
5
  # Gem version
6
- VERSION = "1.2.0"
6
+ VERSION = "1.3.0"
7
7
  end
8
8
  end
@@ -7,6 +7,7 @@ require_relative "./throttled/cooldown"
7
7
  require_relative "./throttled/job"
8
8
  require_relative "./throttled/middlewares/server"
9
9
  require_relative "./throttled/patches/basic_fetch"
10
+ require_relative "./throttled/patches/super_fetch"
10
11
  require_relative "./throttled/registry"
11
12
  require_relative "./throttled/version"
12
13
  require_relative "./throttled/worker"
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: 1.2.0
4
+ version: 1.3.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: 2023-12-18 00:00:00.000000000 Z
11
+ date: 2024-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -69,6 +69,8 @@ files:
69
69
  - lib/sidekiq/throttled/job.rb
70
70
  - lib/sidekiq/throttled/middlewares/server.rb
71
71
  - lib/sidekiq/throttled/patches/basic_fetch.rb
72
+ - lib/sidekiq/throttled/patches/super_fetch.rb
73
+ - lib/sidekiq/throttled/patches/throttled_retriever.rb
72
74
  - lib/sidekiq/throttled/registry.rb
73
75
  - lib/sidekiq/throttled/strategy.rb
74
76
  - lib/sidekiq/throttled/strategy/base.rb
@@ -87,9 +89,9 @@ licenses:
87
89
  - MIT
88
90
  metadata:
89
91
  homepage_uri: https://github.com/ixti/sidekiq-throttled
90
- source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.2.0
92
+ source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.3.0
91
93
  bug_tracker_uri: https://github.com/ixti/sidekiq-throttled/issues
92
- changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.2.0/CHANGES.md
94
+ changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.3.0/CHANGES.md
93
95
  rubygems_mfa_required: 'true'
94
96
  post_install_message:
95
97
  rdoc_options: []
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
108
  - !ruby/object:Gem::Version
107
109
  version: '0'
108
110
  requirements: []
109
- rubygems_version: 3.3.26
111
+ rubygems_version: 3.5.4
110
112
  signing_key:
111
113
  specification_version: 4
112
114
  summary: Concurrency and rate-limit throttling for Sidekiq