sidekiq-throttled 0.18.0 → 1.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/{README.md → README.adoc} +95 -114
  3. data/lib/sidekiq/throttled/job.rb +1 -1
  4. data/lib/sidekiq/throttled/middleware.rb +3 -1
  5. data/lib/sidekiq/throttled/patches/basic_fetch.rb +60 -0
  6. data/lib/sidekiq/throttled/registry.rb +2 -5
  7. data/lib/sidekiq/throttled/strategy/concurrency.rb +2 -4
  8. data/lib/sidekiq/throttled/strategy/threshold.rb +2 -4
  9. data/lib/sidekiq/throttled/strategy.rb +10 -10
  10. data/lib/sidekiq/throttled/strategy_collection.rb +2 -3
  11. data/lib/sidekiq/throttled/version.rb +1 -1
  12. data/lib/sidekiq/throttled/web.rb +2 -45
  13. data/lib/sidekiq/throttled/worker.rb +1 -1
  14. data/lib/sidekiq/throttled.rb +13 -55
  15. metadata +17 -78
  16. data/.coveralls.yml +0 -1
  17. data/.github/dependabot.yml +0 -12
  18. data/.github/workflows/ci.yml +0 -52
  19. data/.gitignore +0 -12
  20. data/.rspec +0 -5
  21. data/.rubocop.yml +0 -20
  22. data/.rubocop_todo.yml +0 -68
  23. data/.travis.yml +0 -37
  24. data/.yardopts +0 -1
  25. data/Appraisals +0 -9
  26. data/CHANGES.md +0 -318
  27. data/Gemfile +0 -34
  28. data/Guardfile +0 -25
  29. data/Rakefile +0 -27
  30. data/gemfiles/sidekiq_6.4.gemfile +0 -33
  31. data/gemfiles/sidekiq_6.5.gemfile +0 -33
  32. data/lib/sidekiq/throttled/communicator/callbacks.rb +0 -72
  33. data/lib/sidekiq/throttled/communicator/exception_handler.rb +0 -25
  34. data/lib/sidekiq/throttled/communicator/listener.rb +0 -109
  35. data/lib/sidekiq/throttled/communicator.rb +0 -116
  36. data/lib/sidekiq/throttled/expirable_list.rb +0 -70
  37. data/lib/sidekiq/throttled/fetch/unit_of_work.rb +0 -83
  38. data/lib/sidekiq/throttled/fetch.rb +0 -94
  39. data/lib/sidekiq/throttled/patches/queue.rb +0 -18
  40. data/lib/sidekiq/throttled/queue_name.rb +0 -46
  41. data/lib/sidekiq/throttled/queues_pauser.rb +0 -152
  42. data/lib/sidekiq/throttled/testing.rb +0 -12
  43. data/lib/sidekiq/throttled/utils.rb +0 -19
  44. data/lib/sidekiq/throttled/web/queues.html.erb +0 -49
  45. data/lib/sidekiq/throttled/web/summary_fix.js +0 -10
  46. data/lib/sidekiq/throttled/web/summary_fix.rb +0 -35
  47. data/rubocop/layout.yml +0 -24
  48. data/rubocop/lint.yml +0 -41
  49. data/rubocop/metrics.yml +0 -4
  50. data/rubocop/performance.yml +0 -25
  51. data/rubocop/rspec.yml +0 -3
  52. data/rubocop/style.yml +0 -84
  53. data/sidekiq-throttled.gemspec +0 -36
  54. /data/{LICENSE.md → LICENSE} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9709e5805bd1bf11ef204afb08a988a4c5998e16ecf8a7a0b8e0c1b4b753ce4d
4
- data.tar.gz: 21b5bdd50945f807e11884a18449be0155cb8bdf2b6ee37b633148b198db615d
3
+ metadata.gz: 714915692e57a08eeea5dd0e0be79f3becfa915669f559f3457509073b89e4fe
4
+ data.tar.gz: 190b4e6d013712725bb64277c00c74c82da5149f73368dbb19890090d638a372
5
5
  SHA512:
6
- metadata.gz: 613164a091883655c4bd879b3dab25198ffc88e49eb7f1e1b0bab33eb2a7eb004b2f6d407e65ccfea52727e347f1b5d8c05015117b5da8500a2a933228044ef4
7
- data.tar.gz: 9b2dde3fd9ecdf25301597bd86609f531f7a8b5d8a90833f7f0d42399501a3d49252fa78af3cc576007cdf8b7025b86223c1a9d1391ab9069c6277220adb7524
6
+ metadata.gz: 7627db53db315ec4acdaf15e715186522c3dbbdc4084aadd65cd0f081845b247f92eb106bcf2e5bf41b5098400adaed00377104b21205b5914495bcacff9d625
7
+ data.tar.gz: 1caca54490b41115389b6ce111c4264a911aba84f656546bce0c62846d6f3828c91a1c681bfb0520f04230c6e113b9d1cd5553c500e6a65a7f6d77c2d36903a2
@@ -1,37 +1,51 @@
1
- # Sidekiq::Throttled
1
+ = Sidekiq::Throttled
2
+ :ci-link: https://github.com/ixti/sidekiq-throttled/actions/workflows/ci.yml
3
+ :ci-badge: https://img.shields.io/github/actions/workflow/status/ixti/sidekiq-throttled/ci.yml?branch=main&style=for-the-badge
4
+ :gem-link: http://rubygems.org/gems/sidekiq-throttled
5
+ :gem-badge: https://img.shields.io/gem/v/sidekiq-throttled?style=for-the-badge
6
+ :doc-link: http://www.rubydoc.info/gems/sidekiq-throttled
7
+ :doc-badge: https://img.shields.io/badge/Documentation-API-blue?style=for-the-badge
2
8
 
3
- [![CI Status](https://github.com/ixti/sidekiq-throttled/actions/workflows/ci.yml/badge.svg)](https://github.com/ixti/sidekiq-throttled/actions/workflows/ci.yml)
4
- [![Latest Version](https://badge.fury.io/rb/sidekiq-throttled.svg)](http://rubygems.org/gems/sidekiq-throttled)
5
- [![API Docs](https://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/sidekiq-throttled)
9
+ ****
10
+ {ci-link}[image:{ci-badge}[CI Status]]
11
+ {gem-link}[image:{gem-badge}[Latest Version]]
12
+ {doc-link}[image:{doc-badge}[API Documentation]]
13
+ ****
6
14
 
7
- Concurrency and threshold throttling for [Sidekiq][sidekiq].
15
+ NOTE: This is the 1.x *development* branch. For the 0.x *stable* branch, please
16
+ see: https://github.com/ixti/sidekiq-throttled/tree/0-x-stable[0-x-stable]
8
17
 
9
- ## Installation
18
+ Concurrency and threshold throttling for https://github.com/mperham/sidekiq[Sidekiq].
19
+
20
+
21
+ == Installation
10
22
 
11
23
  Add this line to your application's Gemfile:
12
24
 
13
- ``` ruby
25
+ [source,ruby]
26
+ ----
14
27
  gem "sidekiq-throttled"
15
- ```
28
+ ----
16
29
 
17
30
  And then execute:
18
31
 
19
- $ bundle
32
+ $ bundle
20
33
 
21
34
  Or install it yourself as:
22
35
 
23
- $ gem install sidekiq-throttled
36
+ $ gem install sidekiq-throttled
24
37
 
25
38
 
26
- ## Usage
39
+ == Usage
27
40
 
28
41
  Add somewhere in your app's bootstrap (e.g. `config/initializers/sidekiq.rb` if
29
42
  you are using Rails):
30
43
 
31
- ``` ruby
44
+ [source,ruby]
45
+ ----
32
46
  require "sidekiq/throttled"
33
47
  Sidekiq::Throttled.setup!
34
- ```
48
+ ----
35
49
 
36
50
  Load order can be an issue if you are using other Sidekiq plugins and/or middleware.
37
51
  To prevent any problems, add the `.setup!` call to the bottom of your init file.
@@ -39,7 +53,8 @@ To prevent any problems, add the `.setup!` call to the bottom of your init file.
39
53
  Once you've done that you can include `Sidekiq::Throttled::Job` to your
40
54
  job classes and configure throttling:
41
55
 
42
- ``` ruby
56
+ [source,ruby]
57
+ ----
43
58
  class MyJob
44
59
  include Sidekiq::Job
45
60
  include Sidekiq::Throttled::Job
@@ -48,37 +63,39 @@ class MyJob
48
63
 
49
64
  sidekiq_throttle(
50
65
  # Allow maximum 10 concurrent jobs of this class at a time.
51
- :concurrency => { :limit => 10 },
66
+ concurrency: { limit: 10 },
52
67
  # Allow maximum 1K jobs being processed within one hour window.
53
- :threshold => { :limit => 1_000, :period => 1.hour }
68
+ threshold: { limit: 1_000, period: 1.hour }
54
69
  )
55
70
 
56
71
  def perform
57
72
  # ...
58
73
  end
59
74
  end
60
- ```
75
+ ----
61
76
 
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:
77
+ TIP: `Sidekiq::Throttled::Job` is aliased as `Sidekiq::Throttled::Worker`,
78
+ thus if you're using `Sidekiq::Worker` naming convention, you can use the
79
+ alias for consistency:
65
80
 
66
- ``` ruby
81
+ [source,ruby]
82
+ ----
67
83
  class MyWorker
68
84
  include Sidekiq::Worker
69
85
  include Sidekiq::Throttled::Worker
70
86
 
71
87
  # ...
72
88
  end
73
- ```
89
+ ----
74
90
 
75
91
 
76
- ### Observer
92
+ === Observer
77
93
 
78
94
  You can specify an observer that will be called on throttling. To do so pass an
79
95
  `:observer` option with callable object:
80
96
 
81
- ``` ruby
97
+ [source,ruby]
98
+ ----
82
99
  class MyJob
83
100
  include Sidekiq::Job
84
101
  include Sidekiq::Throttled::Job
@@ -87,91 +104,95 @@ class MyJob
87
104
  # do something
88
105
  end
89
106
 
90
- sidekiq_options :queue => :my_queue
107
+ sidekiq_options queue: :my_queue
91
108
 
92
109
  sidekiq_throttle(
93
- :concurrency => { :limit => 10 },
94
- :threshold => { :limit => 100, :period => 1.hour }
95
- :observer => MY_OBSERVER
110
+ concurrency: { limit: 10 },
111
+ threshold: { limit: 100, period: 1.hour },
112
+ observer: MY_OBSERVER
96
113
  )
97
114
 
98
115
  def perform(*args)
99
116
  # ...
100
117
  end
101
118
  end
102
- ```
119
+ ----
103
120
 
104
121
  Observer will receive `strategy, *args` arguments, where `strategy` is a Symbol
105
122
  `:concurrency` or `:threshold`, and `*args` are the arguments that were passed
106
123
  to the job.
107
124
 
108
125
 
109
- ### Dynamic throttling
126
+ === Dynamic throttling
110
127
 
111
128
  You can throttle jobs dynamically with `:key_suffix` option:
112
129
 
113
- ``` ruby
130
+ [source,ruby]
131
+ ----
114
132
  class MyJob
115
133
  include Sidekiq::Job
116
134
  include Sidekiq::Throttled::Job
117
135
 
118
- sidekiq_options :queue => :my_queue
136
+ sidekiq_options queue: :my_queue
119
137
 
120
138
  sidekiq_throttle(
121
139
  # Allow maximum 10 concurrent jobs per user at a time.
122
- :concurrency => { :limit => 10, :key_suffix => -> (user_id) { user_id } }
140
+ concurrency: { limit: 10, key_suffix: -> (user_id) { user_id } }
123
141
  )
124
142
 
125
143
  def perform(user_id)
126
144
  # ...
127
145
  end
128
146
  end
129
- ```
147
+ ----
130
148
 
131
149
  You can also supply dynamic values for limits and periods by supplying a proc
132
150
  for these values. The proc will be evaluated at the time the job is fetched
133
151
  and will receive the same arguments that are passed to the job.
134
152
 
135
- ``` ruby
153
+ [source,ruby]
154
+ ----
136
155
  class MyJob
137
156
  include Sidekiq::Job
138
157
  include Sidekiq::Throttled::Job
139
158
 
140
- sidekiq_options :queue => :my_queue
159
+ sidekiq_options queue: :my_queue
141
160
 
142
161
  sidekiq_throttle(
143
162
  # Allow maximum 1000 concurrent jobs of this class at a time for VIPs and 10 for all other users.
144
- :concurrency => {
145
- :limit => ->(user_id) { User.vip?(user_id) ? 1_000 : 10 },
146
- :key_suffix => ->(user_id) { User.vip?(user_id) ? "vip" : "std" }
163
+ concurrency: {
164
+ limit: ->(user_id) { User.vip?(user_id) ? 1_000 : 10 },
165
+ key_suffix: ->(user_id) { User.vip?(user_id) ? "vip" : "std" }
147
166
  },
148
167
  # Allow 1000 jobs/hour to be processed for VIPs and 10/day for all others
149
- :threshold => {
150
- :limit => ->(user_id) { User.vip?(user_id) ? 1_000 : 10 },
151
- :period => ->(user_id) { User.vip?(user_id) ? 1.hour : 1.day },
152
- :key_suffix => ->(user_id) { User.vip?(user_id) ? "vip" : "std" }
168
+ threshold: {
169
+ limit: ->(user_id) { User.vip?(user_id) ? 1_000 : 10 },
170
+ period: ->(user_id) { User.vip?(user_id) ? 1.hour : 1.day },
171
+ key_suffix: ->(user_id) { User.vip?(user_id) ? "vip" : "std" }
172
+ }
153
173
  )
154
174
 
155
175
  def perform(user_id)
156
176
  # ...
157
177
  end
158
178
  end
159
- ```
179
+ ----
160
180
 
161
181
  You also can use several different keys to throttle one worker.
162
182
 
163
- ``` ruby
183
+ [source,ruby]
184
+ ----
164
185
  class MyJob
165
186
  include Sidekiq::Job
166
187
  include Sidekiq::Throttled::Job
167
188
 
168
- sidekiq_options :queue => :my_queue
189
+ sidekiq_options queue: :my_queue
169
190
 
170
191
  sidekiq_throttle(
171
192
  # Allow maximum 10 concurrent jobs per project at a time and maximum 2 jobs per user
172
- :concurrency => [
173
- { :limit => 10, :key_suffix => -> (project_id, user_id) { project_id } },
174
- { :limit => 2, :key_suffix => -> (project_id, user_id) { user_id } }
193
+ concurrency: [
194
+ { limit: 10, key_suffix: -> (project_id, user_id) { project_id } },
195
+ { limit: 2, key_suffix: -> (project_id, user_id) { user_id } }
175
196
  ]
176
197
  # For :threshold it works the same
177
198
  )
@@ -180,14 +201,14 @@ class MyJob
180
201
  # ...
181
202
  end
182
203
  end
183
- ```
204
+ ----
184
205
 
185
- **NB** Don't forget to specify `:key_suffix` and make it return different values
186
- if you are using dynamic limit/period options. Otherwise you risk getting into
187
- some trouble.
206
+ IMPORTANT: Don't forget to specify `:key_suffix` and make it return different
207
+ values if you are using dynamic limit/period options. Otherwise, you risk
208
+ getting into some trouble.
188
209
 
189
210
 
190
- ### Concurrency throttling fine-tuning
211
+ === Concurrency throttling fine-tuning
191
212
 
192
213
  Concurrency throttling is based on distributed locks. Those locks have default
193
214
  time to live (TTL) set to 15 minutes. If your job takes more than 15 minutes
@@ -200,53 +221,21 @@ OOM-killed) cleanup middleware wasn't executed and locks were not released.
200
221
  If your job takes more than 15 minutes to complete, you can tune concurrency
201
222
  lock TTL to fit your needs:
202
223
 
203
- ``` ruby
224
+ [source,ruby]
225
+ ----
204
226
  # Set concurrency strategy lock TTL to 1 hour.
205
- sidekiq_throttle(:concurrency => { :limit => 20, :ttl => 1.hour.to_i })
206
- ```
207
-
208
-
209
- ## Enhanced Queues list
210
-
211
- This gem provides ability to pause/resume queues from processing by workers.
212
- So you may simply pause particular queue without need to stop and reconfigure
213
- workers by simply pushing a button on sidekiq web UI.
214
-
215
- By default we add *Enhanced Queues* tab with this functionality. But if you
216
- want you can override default *Queues* tab completely (notice that page will
217
- still be available using it's URL, but tab will be pointing enhanced version).
218
- To do so, just call `Sidekiq::Throttled::Web.enhance_queues_tab!` somewhere
219
- in your initializer/bootstrap code. If you are using rails, you might want to
220
- add it right into your `config/routes.rb` file:
221
-
222
- ``` ruby
223
- # file config/routes.rb
224
-
225
- require "sidekiq/web"
226
- require "sidekiq/throttled/web"
227
-
228
- Rails.application.routes.draw do
229
- # ...
227
+ sidekiq_throttle(concurrency: { limit: 20, ttl: 1.hour.to_i })
228
+ ----
230
229
 
231
- # Replace Sidekiq Queues with enhanced version!
232
- Sidekiq::Throttled::Web.enhance_queues_tab!
233
230
 
234
- # Mount Sidekiq Web UI to `/sidekiq` endpoint
235
- mount Sidekiq::Web => "/sidekiq"
231
+ == Supported Ruby Versions
236
232
 
237
- # ...
238
- end
239
- ```
240
-
241
-
242
- ## Supported Ruby Versions
243
-
244
- This library aims to support and is [tested against][ci] the following Ruby
245
- versions:
233
+ This library aims to support and is tested against the following Ruby versions:
246
234
 
247
235
  * Ruby 2.7.x
248
236
  * Ruby 3.0.x
249
237
  * Ruby 3.1.x
238
+ * Ruby 3.2.x
250
239
 
251
240
  If something doesn't work on one of these versions, it's a bug.
252
241
 
@@ -262,15 +251,24 @@ exist at the time of a major release, support for that Ruby version may be
262
251
  dropped.
263
252
 
264
253
 
265
- ## Supported Sidekiq Versions
254
+ == Supported Sidekiq Versions
266
255
 
267
- This library aims to support work with following [Sidekiq][sidekiq] versions:
256
+ This library aims to support and work with following Sidekiq versions:
268
257
 
269
- * Sidekiq 6.4.x
270
258
  * Sidekiq 6.5.x
259
+ * Sidekiq 7.0.x
260
+ * Sidekiq 7.1.x
261
+
262
+
263
+ == Development
271
264
 
265
+ bundle install
266
+ bundle exec appraisal generate
267
+ bundle exec appraisal install
268
+ bundle exec rake
272
269
 
273
- ## Contributing
270
+
271
+ == Contributing
274
272
 
275
273
  * Fork sidekiq-throttled on GitHub
276
274
  * Make your changes
@@ -278,20 +276,3 @@ This library aims to support work with following [Sidekiq][sidekiq] versions:
278
276
  * Send a pull request
279
277
  * If we like them we'll merge them
280
278
  * If we've accepted a patch, feel free to ask for commit access!
281
-
282
-
283
- ## Development
284
-
285
- ```
286
- bundle update
287
- bundle exec appraisal install # install dependencies for all gemfiles
288
- bundle exec appraisal update # update dependencies for all gemfiles
289
- bundle exec appraisal rspec # run rspec against each gemfile
290
- bundle exec rubocop # run static code analysis
291
- ```
292
-
293
- Don't forget to run `appraisal update` after any changes to `Gemfile`.
294
-
295
-
296
- [ci]: https://github.com/ixti/sidekiq-throttled/actions/workflows/ci.yml
297
- [sidekiq]: https://github.com/mperham/sidekiq
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # internal
4
- require "sidekiq/throttled/registry"
4
+ require_relative "./registry"
5
5
 
6
6
  module Sidekiq
7
7
  module Throttled
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # internal
4
- require "sidekiq/throttled/registry"
4
+ require_relative "./registry"
5
5
 
6
6
  module Sidekiq
7
7
  module Throttled
@@ -9,6 +9,8 @@ module Sidekiq
9
9
  #
10
10
  # @private
11
11
  class Middleware
12
+ include Sidekiq::ServerMiddleware if Sidekiq::VERSION >= "6.5.0"
13
+
12
14
  # Called within Sidekiq job processing
13
15
  def call(_worker, msg, _queue)
14
16
  yield
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq"
4
+ require "sidekiq/fetch"
5
+
6
+ module Sidekiq
7
+ module Throttled
8
+ module Patches
9
+ module BasicFetch
10
+ class << self
11
+ def apply!
12
+ Sidekiq::BasicFetch.prepend(self) unless Sidekiq::BasicFetch.include?(self)
13
+ end
14
+ end
15
+
16
+ # Retrieves job from redis.
17
+ #
18
+ # @return [Sidekiq::Throttled::UnitOfWork, nil]
19
+ def retrieve_work
20
+ work = super
21
+
22
+ if work && Throttled.throttled?(work.job)
23
+ requeue_throttled(work)
24
+ return nil
25
+ end
26
+
27
+ work
28
+ end
29
+
30
+ private
31
+
32
+ # Pushes job back to the head of the queue, so that job won't be tried
33
+ # immediately after it was requeued (in most cases).
34
+ #
35
+ # @note This is triggered when job is throttled. So it is same operation
36
+ # Sidekiq performs upon `Sidekiq::Worker.perform_async` call.
37
+ #
38
+ # @return [void]
39
+ def requeue_throttled(work)
40
+ redis { |conn| conn.lpush(work.queue, work.job) }
41
+ end
42
+
43
+ # Returns list of queues to try to fetch jobs from.
44
+ #
45
+ # @note It may return an empty array.
46
+ # @param [Array<String>] queues
47
+ # @return [Array<String>]
48
+ def queues_cmd
49
+ queues = super
50
+
51
+ # TODO: Refactor to be prepended as an integration mixin during configuration stage
52
+ # Or via configurable queues reducer
53
+ queues -= Sidekiq::Pauzer.paused_queues.map { |name| "queue:#{name}" } if defined?(Sidekiq::Pauzer)
54
+
55
+ queues
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # internal
4
- require "sidekiq/throttled/strategy"
5
- require "sidekiq/throttled/utils"
4
+ require_relative "./strategy"
6
5
 
7
6
  module Sidekiq
8
7
  module Throttled
@@ -14,8 +13,6 @@ module Sidekiq
14
13
  @aliases = {}
15
14
 
16
15
  class << self
17
- include Utils
18
-
19
16
  # Adds strategy to the registry.
20
17
  #
21
18
  # @param (see Strategy#initialize)
@@ -107,7 +104,7 @@ module Sidekiq
107
104
  def find_by_class(name)
108
105
  return unless Throttled.configuration.inherit_strategies?
109
106
 
110
- const = name.is_a?(Class) ? name : constantize(name)
107
+ const = name.is_a?(Class) ? name : Object.const_get(name)
111
108
  return unless const.is_a?(Class)
112
109
 
113
110
  const.ancestors.each do |m|
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "redis_prescription"
4
4
 
5
- require "sidekiq/throttled/strategy/base"
5
+ require_relative "./base"
6
6
 
7
7
  module Sidekiq
8
8
  module Throttled
@@ -49,9 +49,7 @@ module Sidekiq
49
49
  keys = [key(job_args)]
50
50
  argv = [jid.to_s, job_limit, @ttl, Time.now.to_f]
51
51
 
52
- Sidekiq.redis do |redis|
53
- 1 == SCRIPT.call(redis, :keys => keys, :argv => argv)
54
- end
52
+ Sidekiq.redis { |redis| 1 == SCRIPT.call(redis, keys: keys, argv: argv) }
55
53
  end
56
54
 
57
55
  # @return [Integer] Current count of jobs
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "redis_prescription"
4
4
 
5
- require "sidekiq/throttled/strategy/base"
5
+ require_relative "./base"
6
6
 
7
7
  module Sidekiq
8
8
  module Throttled
@@ -66,9 +66,7 @@ module Sidekiq
66
66
  keys = [key(job_args)]
67
67
  argv = [job_limit, period(job_args), Time.now.to_f]
68
68
 
69
- Sidekiq.redis do |redis|
70
- 1 == SCRIPT.call(redis, :keys => keys, :argv => argv)
71
- end
69
+ Sidekiq.redis { |redis| 1 == SCRIPT.call(redis, keys: keys, argv: argv) }
72
70
  end
73
71
 
74
72
  # @return [Integer] Current count of jobs
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # internal
4
- require "sidekiq/throttled/errors"
5
- require "sidekiq/throttled/strategy_collection"
6
- require "sidekiq/throttled/strategy/concurrency"
7
- require "sidekiq/throttled/strategy/threshold"
4
+ require_relative "./errors"
5
+ require_relative "./strategy_collection"
6
+ require_relative "./strategy/concurrency"
7
+ require_relative "./strategy/threshold"
8
8
 
9
9
  module Sidekiq
10
10
  module Throttled
@@ -35,14 +35,14 @@ module Sidekiq
35
35
  @observer = observer
36
36
 
37
37
  @concurrency = StrategyCollection.new(concurrency,
38
- :strategy => Concurrency,
39
- :name => name,
40
- :key_suffix => key_suffix)
38
+ strategy: Concurrency,
39
+ name: name,
40
+ key_suffix: key_suffix)
41
41
 
42
42
  @threshold = StrategyCollection.new(threshold,
43
- :strategy => Threshold,
44
- :name => name,
45
- :key_suffix => key_suffix)
43
+ strategy: Threshold,
44
+ name: name,
45
+ key_suffix: key_suffix)
46
46
 
47
47
  return if @concurrency.any? || @threshold.any?
48
48
 
@@ -19,8 +19,7 @@ module Sidekiq
19
19
  # @param [#to_s] name
20
20
  # @param [#call] key_suffix Dynamic key suffix generator.
21
21
  def initialize(strategies, strategy:, name:, key_suffix:)
22
- strategies = (strategies.is_a?(Hash) ? [strategies] : Array(strategies))
23
- @strategies = strategies.map do |options|
22
+ @strategies = (strategies.is_a?(Hash) ? [strategies] : Array(strategies)).map do |options|
24
23
  make_strategy(strategy, name, key_suffix, options)
25
24
  end
26
25
  end
@@ -61,7 +60,7 @@ module Sidekiq
61
60
  return unless options
62
61
 
63
62
  strategy.new("throttled:#{name}",
64
- :key_suffix => key_suffix,
63
+ key_suffix: key_suffix,
65
64
  **options)
66
65
  end
67
66
  end
@@ -3,6 +3,6 @@
3
3
  module Sidekiq
4
4
  module Throttled
5
5
  # Gem version
6
- VERSION = "0.18.0"
6
+ VERSION = "1.0.0.alpha.1"
7
7
  end
8
8
  end