sidekiq-throttled 0.13.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b1f0237b14be26ff2b25aeaedd80e4029610cfa7c2be331827c5b865c338f48
4
- data.tar.gz: 3a5be191a1f02b2ce21b766be820201b6f4d06b74323456412096a0beef38d11
3
+ metadata.gz: 149c9477c7a02b5a8a48fd0f9d1a665c1cd254a2b5af92c82bb0bbcda92c7907
4
+ data.tar.gz: 2fe05d0217edbdb5e9a66fdbd29149824ba5623d5c2e5d5df2db269d4a003bfc
5
5
  SHA512:
6
- metadata.gz: e9da0e99d328b6825ab3f47e1ea94c255717a01d05e28c90399aaf826a8d43a0e10de82baee329ddd8d846ac4e4ff0cb6f09ef11277fef2143972c50b2c3a55b
7
- data.tar.gz: d73d011be01f319460fe87fda608aea9550e1f560bf778dfd5628874f0f074fc2020ad5e2f36ec8413a349c6dcd620f7aaa84a48f15e59dab8bf508e3e769354
6
+ metadata.gz: 165176da74bbeaa33d3f882c8cac2f61e1796184dfcfedb737a9604d49cad86d20c1a9b7a19c8272a7302164825036bcea3a0a2dc78c0312db7dd1ac19f5c64a
7
+ data.tar.gz: 6db474ddc907ee5c97d3b9eb829a338c9a28d5997346031864cbfcda00857a24b49ae36451f92bf112d0985065bbf72443313733bc13075c8e1ebdcab6465c70
@@ -2,20 +2,19 @@ name: CI
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
5
+ branches: [ main ]
6
6
  pull_request:
7
- branches: [ master ]
7
+ branches: [ main ]
8
8
 
9
9
  jobs:
10
- rspec:
10
+ test:
11
11
  name: "rspec (ruby:${{ matrix.ruby }} sidekiq:${{ matrix.sidekiq }})"
12
12
 
13
13
  strategy:
14
+ fail-fast: false
14
15
  matrix:
15
- ruby: [ "2.4", "2.5", "2.6", "2.7" ]
16
- sidekiq: [ "5.0", "5.1", "5.2", "6.0" ]
17
- exclude:
18
- - { ruby: "2.4", sidekiq: "6.0" }
16
+ ruby: [ "2.7", "3.0", "3.1" ]
17
+ sidekiq: [ "6.0", "6.1", "6.2", "6.3", "6.4", "6.5" ]
19
18
 
20
19
  runs-on: ubuntu-latest
21
20
 
@@ -26,7 +25,7 @@ jobs:
26
25
  options: "--entrypoint redis-server"
27
26
 
28
27
  env:
29
- GEMFILE: gemfiles/sidekiq_${{ matrix.sidekiq }}.gemfile
28
+ BUNDLE_GEMFILE: gemfiles/sidekiq_${{ matrix.sidekiq }}.gemfile
30
29
 
31
30
  steps:
32
31
  - uses: actions/checkout@v2
@@ -34,11 +33,10 @@ jobs:
34
33
  - uses: ruby/setup-ruby@v1
35
34
  with:
36
35
  ruby-version: ${{ matrix.ruby }}
36
+ bundler-cache: true
37
37
 
38
- - name: bundle install
39
- run: bundle install --without development --jobs 4 --retry 3
40
-
41
- - run: bundle exec rspec
38
+ - name: bundle exec rspec
39
+ run: bundle exec rspec --format progress --force-colour
42
40
 
43
41
  rubocop:
44
42
  runs-on: ubuntu-latest
@@ -48,9 +46,7 @@ jobs:
48
46
 
49
47
  - uses: ruby/setup-ruby@v1
50
48
  with:
51
- ruby-version: "2.4"
52
-
53
- - name: bundle install
54
- run: bundle install --without development --jobs 4 --retry 3
49
+ ruby-version: "2.7"
50
+ bundler-cache: true
55
51
 
56
52
  - run: bundle exec rubocop
data/.rubocop.yml CHANGED
@@ -1,100 +1,20 @@
1
- inherit_from:
2
- - .rubocop_todo.yml
3
-
4
1
  require:
2
+ - rubocop-performance
3
+ - rubocop-rake
5
4
  - rubocop-rspec
6
5
 
7
- ################################################################################
6
+ inherit_from:
7
+ - .rubocop_todo.yml
8
+ - rubocop/layout.yml
9
+ - rubocop/lint.yml
10
+ - rubocop/metrics.yml
11
+ - rubocop/performance.yml
12
+ - rubocop/rspec.yml
13
+ - rubocop/style.yml
8
14
 
9
15
  AllCops:
10
- DisplayCopNames: true
11
- TargetRubyVersion: 2.4
12
16
  Exclude:
13
- - "gemfiles/*"
14
-
15
- ## Layout ######################################################################
16
-
17
- Layout/ArgumentAlignment:
18
- EnforcedStyle: with_fixed_indentation
19
-
20
- Layout/FirstArrayElementIndentation:
21
- EnforcedStyle: consistent
22
-
23
- Layout/FirstHashElementIndentation:
24
- EnforcedStyle: consistent
25
-
26
- Layout/HashAlignment:
27
- EnforcedHashRocketStyle: table
28
-
29
- Layout/LineLength:
30
- Max: 100
31
-
32
- Layout/MultilineMethodCallIndentation:
33
- EnforcedStyle: indented
34
-
35
- Layout/ParameterAlignment:
36
- EnforcedStyle: with_fixed_indentation
37
-
38
- Layout/SpaceAroundMethodCallOperator:
39
- Enabled: true
40
-
41
- Layout/SpaceInLambdaLiteral:
42
- EnforcedStyle: require_space
43
-
44
- ## Lint ########################################################################
45
-
46
- Lint/RaiseException:
47
- Enabled: true
48
-
49
- Lint/StructNewOverride:
50
- Enabled: true
51
-
52
- ## Metrics #####################################################################
53
-
54
- Metrics/BlockLength:
55
- Exclude:
56
- - "Guardfile"
57
- - "spec/**/*"
58
-
59
- ## Styles ######################################################################
60
-
61
- Style/Documentation:
62
- Enabled: false
63
-
64
- Style/ExponentialNotation:
65
- Enabled: true
66
-
67
- Style/HashEachMethods:
68
- Enabled: true
69
-
70
- Style/HashSyntax:
71
- EnforcedStyle: hash_rockets
72
-
73
- Style/HashTransformKeys:
74
- Enabled: true
75
-
76
- Style/HashTransformValues:
77
- Enabled: true
78
-
79
- # Follow your heart where it makes sense to use lambda or lambda literal.
80
- # Enforcing it makes some pieces of code look REALLY terrible, e.g. in
81
- # case of empty (noop) lambdas: `lambda { |_| }`.
82
- Style/Lambda:
83
- Enabled: false
84
-
85
- # Enabling this cop makes Guardfile (which is full of pathname regexps)
86
- # look absolutley style-inconsistent and terrible. In any case, this should
87
- # be on developer's choice whenever to use `%r` or not. Just like we don't
88
- # enforce to use `["foo"]` over `%w(foo)` and so on.
89
- Style/RegexpLiteral:
90
- Enabled: false
91
-
92
- Style/RescueStandardError:
93
- EnforcedStyle: implicit
94
-
95
- Style/StringLiterals:
96
- EnforcedStyle: double_quotes
97
-
98
- # I prefer Yoda style instead, but there's no such enforcement style.
99
- Style/YodaCondition:
100
- Enabled: false
17
+ - gemfiles/**/*
18
+ - vendor/**/*
19
+ NewCops: enable
20
+ TargetRubyVersion: 2.7
data/.rubocop_todo.yml CHANGED
@@ -1,57 +1,68 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-09-10 23:47:55 +0000 using RuboCop version 0.58.2.
3
+ # on 2022-06-13 00:11:28 UTC using RuboCop version 1.30.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 5
10
- # Configuration parameters: CountComments.
11
- Metrics/MethodLength:
12
- Max: 13
9
+ # Offense count: 3
10
+ # Configuration parameters: AllowComments, AllowEmptyLambdas.
11
+ Lint/EmptyBlock:
12
+ Exclude:
13
+ - 'spec/sidekiq/throttled/middleware_spec.rb'
14
+ - 'spec/sidekiq/throttled/registry_spec.rb'
13
15
 
14
- # Offense count: 25
15
- # Configuration parameters: Max.
16
- RSpec/ExampleLength:
16
+ # Offense count: 2
17
+ # Configuration parameters: EnforcedStyleForLeadingUnderscores.
18
+ # SupportedStylesForLeadingUnderscores: disallowed, required, optional
19
+ Naming/MemoizedInstanceVariableName:
20
+ Exclude:
21
+ - 'lib/sidekiq/throttled/communicator.rb'
22
+ - 'lib/sidekiq/throttled/queues_pauser.rb'
23
+
24
+ # Offense count: 2
25
+ Performance/MethodObjectAsBlock:
26
+ Exclude:
27
+ - 'lib/sidekiq/throttled/queues_pauser.rb'
28
+
29
+ # Offense count: 2
30
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
31
+ # Include: **/*_spec*rb*, **/spec/**/*
32
+ RSpec/FilePath:
17
33
  Exclude:
18
- - 'spec/sidekiq/throttled/communicator/callbacks_spec.rb'
19
- - 'spec/sidekiq/throttled/communicator/listener_spec.rb'
20
- - 'spec/sidekiq/throttled/communicator_spec.rb'
21
- - 'spec/sidekiq/throttled/fetch_spec.rb'
22
- - 'spec/sidekiq/throttled/queues_pauser_spec.rb'
23
- - 'spec/sidekiq/throttled/strategy_spec.rb'
24
34
  - 'spec/sidekiq/throttled/web/queues_spec.rb'
25
- - 'spec/sidekiq/throttled_spec.rb'
35
+ - 'spec/sidekiq/throttled/web/throttled_spec.rb'
26
36
 
27
- # Offense count: 62
37
+ # Offense count: 69
28
38
  # Configuration parameters: .
29
39
  # SupportedStyles: have_received, receive
30
40
  RSpec/MessageSpies:
31
41
  EnforcedStyle: receive
32
42
 
33
- # Offense count: 20
34
- # Configuration parameters: AggregateFailuresByDefault.
43
+ # Offense count: 22
35
44
  RSpec/MultipleExpectations:
36
45
  Max: 4
37
46
 
38
- # Offense count: 33
47
+ # Offense count: 7
48
+ # Configuration parameters: AllowSubject.
49
+ RSpec/MultipleMemoizedHelpers:
50
+ Max: 6
51
+
52
+ # Offense count: 46
39
53
  RSpec/NestedGroups:
40
54
  Max: 5
41
55
 
42
- # Offense count: 3
43
- RSpec/SubjectStub:
56
+ # Offense count: 5
57
+ RSpec/StubbedMock:
44
58
  Exclude:
45
- - 'spec/sidekiq/throttled/communicator_spec.rb'
59
+ - 'spec/sidekiq/throttled/expirable_list_spec.rb'
60
+ - 'spec/sidekiq/throttled/fetch_spec.rb'
46
61
  - 'spec/sidekiq/throttled/queues_pauser_spec.rb'
47
62
 
48
- # Offense count: 1
49
- # Configuration parameters: IgnoreSymbolicNames.
50
- RSpec/VerifiedDoubles:
51
- Exclude:
52
- - 'spec/sidekiq/throttled/registry_spec.rb'
53
-
54
- # Offense count: 1
55
- Security/MarshalLoad:
63
+ # Offense count: 6
64
+ RSpec/SubjectStub:
56
65
  Exclude:
57
- - 'lib/sidekiq/throttled/communicator/listener.rb'
66
+ - 'spec/sidekiq/throttled/communicator_spec.rb'
67
+ - 'spec/sidekiq/throttled/fetch_spec.rb'
68
+ - 'spec/sidekiq/throttled/queues_pauser_spec.rb'
data/Appraisals CHANGED
@@ -1,21 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise "sidekiq-5.0" do
4
- gem "sidekiq", "~> 5.0.0"
3
+ appraise "sidekiq-6.0" do
4
+ gem "sidekiq", "~> 6.0.0"
5
5
  end
6
6
 
7
- appraise "sidekiq-5.1" do
8
- gem "sidekiq", "~> 5.1.0"
7
+ appraise "sidekiq-6.1" do
8
+ gem "sidekiq", "~> 6.1.0"
9
9
  end
10
10
 
11
- appraise "sidekiq-5.2" do
12
- gem "sidekiq", "~> 5.2.0"
11
+ appraise "sidekiq-6.2" do
12
+ gem "sidekiq", "~> 6.2.0"
13
13
  end
14
14
 
15
- appraise "sidekiq-6.0" do
16
- gem "sidekiq", "~> 6.0.0"
15
+ appraise "sidekiq-6.3" do
16
+ gem "sidekiq", "~> 6.3.0"
17
17
  end
18
18
 
19
- appraise "sidekiq-6.1" do
20
- gem "sidekiq", "~> 6.1.0"
19
+ appraise "sidekiq-6.4" do
20
+ gem "sidekiq", "~> 6.4.0"
21
+ end
22
+
23
+ appraise "sidekiq-6.5" do
24
+ gem "sidekiq", "~> 6.5.0"
21
25
  end
data/CHANGES.md CHANGED
@@ -1,3 +1,56 @@
1
+ ## 0.16.0 (2022-06-13)
2
+
3
+ * Drop Ruby 2.6 support.
4
+
5
+ * Drop Sidekiq 5.X support.
6
+
7
+ * [#121](https://github.com/sensortower/sidekiq-throttled/pull/121)
8
+ Sidekiq 6.5 compatibility.
9
+ ([@hieuk09])
10
+
11
+ * [#116](https://github.com/sensortower/sidekiq-throttled/pull/116)
12
+ Unwrap ActiveJob JobWrapper
13
+ ([@holstvoogd])
14
+
15
+ * [#115](https://github.com/sensortower/sidekiq-throttled/pull/115)
16
+ Fix Redis 4.6 deprecation warnings.
17
+ ([@dbackeus])
18
+
19
+ * [#113](https://github.com/sensortower/sidekiq-throttled/pull/113)
20
+ Add Ruby 3.1 to CI.
21
+ ([@petergoldstein])
22
+
23
+ * [#103](https://github.com/sensortower/sidekiq-throttled/pull/103)
24
+ Rename Sidekiq::Throttled::Worker to Sidekiq::Throttled::Job, and alias it
25
+ as Sidekiq::Throttled::Worker.
26
+ ([@CHTJonas])
27
+
28
+ ## 0.15.0 (2021-12-16)
29
+
30
+ * [#102](https://github.com/sensortower/sidekiq-throttled/pull/102)
31
+ Support Ruby 3.0 and Sidekiq 6.2+.
32
+ ([@ybiquitous])
33
+
34
+ * [#97](https://github.com/sensortower/sidekiq-throttled/pull/97)
35
+ Fix kwargs usage in strategy collection.
36
+ ([@baptistejub])
37
+
38
+ ## 0.14.0 (2021-09-21)
39
+
40
+ * [#98](https://github.com/sensortower/sidekiq-throttled/pull/98)
41
+ Remove warning for strategy override.
42
+ ([@mattiagiuffrida-st])
43
+
44
+ * [#65](https://github.com/sensortower/sidekiq-throttled/pull/65)
45
+ Support composite (multi-key) strategies.
46
+ ([@holyketzer])
47
+
48
+ * [#89](https://github.com/sensortower/sidekiq-throttled/pull/89),
49
+ [#96](https://github.com/sensortower/sidekiq-throttled/pull/96), and
50
+ [#93](https://github.com/sensortower/sidekiq-throttled/pull/93)
51
+ Improve documentation.
52
+ ([@hubertjakubiak], [@khaile], and [@kylerippey])
53
+
1
54
  ## 0.13.0 (2020-07-28)
2
55
 
3
56
  * [#85](https://github.com/sensortower/sidekiq-throttled/pull/85)
@@ -221,3 +274,15 @@
221
274
  [@lenon]: https://github.com/lenon
222
275
  [@vaot]: https://github.com/vaot
223
276
  [@hmaack]: https://github.com/hmaack
277
+ [@holyketzer]: https://github.com/holyketzer
278
+ [@hubertjakubiak]: https://github.com/hubertjakubiak
279
+ [@kylerippey]: https://github.com/kylerippey
280
+ [@khaile]: https://github.com/khaile
281
+ [@mattiagiuffrida-st]: https://github.com/mattiagiuffrida-st
282
+ [@baptistejub]: https://github.com/baptistejub
283
+ [@ybiquitous]: https://github.com/ybiquitous
284
+ [@hieuk09]: https://github.com/hieuk09
285
+ [@petergoldstein]: https://github.com/petergoldstein
286
+ [@dbackeus]: https://github.com/dbackeus
287
+ [@holstvoogd]: https://github.com/holstvoogd
288
+ [@CHTJonas]: https://github.com/CHTJonas
data/Gemfile CHANGED
@@ -5,9 +5,6 @@ source "https://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "rake"
7
7
  gem "rspec"
8
- gem "rubocop", "~> 0.82.0", :require => false
9
- gem "rubocop-performance", "~>1.5.2", :require => false
10
- gem "rubocop-rspec", "~> 1.39.0", :require => false
11
8
  gem "sidekiq"
12
9
 
13
10
  group :development do
@@ -20,13 +17,18 @@ end
20
17
  group :test do
21
18
  gem "apparition"
22
19
  gem "capybara"
23
- gem "coveralls", :require => false
24
20
  gem "puma"
25
21
  gem "rack-test"
26
- gem "simplecov"
27
22
  gem "sinatra"
28
23
  gem "timecop"
29
24
  end
30
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
+
31
33
  # Specify your gem's dependencies in sidekiq-throttled.gemspec
32
34
  gemspec
data/LICENSE.md CHANGED
@@ -1,5 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
+ Copyright (c) 2022 Alexey Zapparov
4
+ Copyright (c) 2020-2021 Alexey Zapparov, SensorTower Inc.
3
5
  Copyright (c) 2015-2020 SensorTower Inc.
4
6
 
5
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
data/README.md CHANGED
@@ -1,10 +1,7 @@
1
1
  # Sidekiq::Throttled
2
2
 
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)
3
4
  [![Latest Version](https://badge.fury.io/rb/sidekiq-throttled.svg)](http://rubygems.org/gems/sidekiq-throttled)
4
- [![CI Status](https://github.com/sensortower/sidekiq-throttled/workflows/CI/badge.svg?branch=master)](https://github.com/sensortower/sidekiq-throttled/actions?query=workflow%3ACI+branch%3Amaster)
5
- [![Code Quality](https://codeclimate.com/github/sensortower/sidekiq-throttled.svg?branch=master)](https://codeclimate.com/github/sensortower/sidekiq-throttled)
6
- [![Code Coverage](https://coveralls.io/repos/github/sensortower/sidekiq-throttled/badge.svg?branch=master)](https://coveralls.io/github/sensortower/sidekiq-throttled?branch=master)
7
- [![API Docs Quality](http://inch-ci.org/github/sensortower/sidekiq-throttled.svg?branch=master)](http://inch-ci.org/github/sensortower/sidekiq-throttled)
8
5
  [![API Docs](https://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/sidekiq-throttled)
9
6
 
10
7
  Concurrency and threshold throttling for [Sidekiq][sidekiq].
@@ -49,12 +46,12 @@ class MyWorker
49
46
 
50
47
  sidekiq_options :queue => :my_queue
51
48
 
52
- sidekiq_throttle({
49
+ sidekiq_throttle(
53
50
  # Allow maximum 10 concurrent jobs of this class at a time.
54
51
  :concurrency => { :limit => 10 },
55
52
  # Allow maximum 1K jobs being processed within one hour window.
56
53
  :threshold => { :limit => 1_000, :period => 1.hour }
57
- })
54
+ )
58
55
 
59
56
  def perform
60
57
  # ...
@@ -78,11 +75,11 @@ class MyWorker
78
75
 
79
76
  sidekiq_options :queue => :my_queue
80
77
 
81
- sidekiq_throttle({
78
+ sidekiq_throttle(
82
79
  :concurrency => { :limit => 10 },
83
80
  :threshold => { :limit => 100, :period => 1.hour }
84
81
  :observer => MY_OBSERVER
85
- })
82
+ )
86
83
 
87
84
  def perform(*args)
88
85
  # ...
@@ -106,10 +103,10 @@ class MyWorker
106
103
 
107
104
  sidekiq_options :queue => :my_queue
108
105
 
109
- sidekiq_throttle({
106
+ sidekiq_throttle(
110
107
  # Allow maximum 10 concurrent jobs per user at a time.
111
108
  :concurrency => { :limit => 10, :key_suffix => -> (user_id) { user_id } }
112
- })
109
+ )
113
110
 
114
111
  def perform(user_id)
115
112
  # ...
@@ -128,7 +125,7 @@ class MyWorker
128
125
 
129
126
  sidekiq_options :queue => :my_queue
130
127
 
131
- sidekiq_throttle({
128
+ sidekiq_throttle(
132
129
  # Allow maximum 1000 concurrent jobs of this class at a time for VIPs and 10 for all other users.
133
130
  :concurrency => {
134
131
  :limit => ->(user_id) { User.vip?(user_id) ? 1_000 : 10 },
@@ -139,7 +136,7 @@ class MyWorker
139
136
  :limit => ->(user_id) { User.vip?(user_id) ? 1_000 : 10 },
140
137
  :period => ->(user_id) { User.vip?(user_id) ? 1.hour : 1.day },
141
138
  :key_suffix => ->(user_id) { User.vip?(user_id) ? "vip" : "std" }
142
- })
139
+ )
143
140
 
144
141
  def perform(user_id)
145
142
  # ...
@@ -147,6 +144,30 @@ class MyWorker
147
144
  end
148
145
  ```
149
146
 
147
+ You also can use several different keys to throttle one worker.
148
+
149
+ ``` ruby
150
+ class MyWorker
151
+ include Sidekiq::Worker
152
+ include Sidekiq::Throttled::Worker
153
+
154
+ sidekiq_options :queue => :my_queue
155
+
156
+ sidekiq_throttle(
157
+ # Allow maximum 10 concurrent jobs per project at a time and maximum 2 jobs per user
158
+ :concurrency => [
159
+ { :limit => 10, :key_suffix => -> (project_id, user_id) { project_id } },
160
+ { :limit => 2, :key_suffix => -> (project_id, user_id) { user_id } }
161
+ ]
162
+ # For :threshold it works the same
163
+ )
164
+
165
+ def perform(project_id, user_id)
166
+ # ...
167
+ end
168
+ end
169
+ ```
170
+
150
171
  **NB** Don't forget to specify `:key_suffix` and make it return different values
151
172
  if you are using dynamic limit/period options. Otherwise you risk getting into
152
173
  some trouble.
@@ -206,12 +227,12 @@ end
206
227
 
207
228
  ## Supported Ruby Versions
208
229
 
209
- This library aims to support and is [tested against][travis] the following Ruby
230
+ This library aims to support and is [tested against][ci] the following Ruby
210
231
  versions:
211
232
 
212
- * Ruby 2.4.x
213
- * Ruby 2.5.x
214
- * Ruby 2.6.x
233
+ * Ruby 2.7.x
234
+ * Ruby 3.0.x
235
+ * Ruby 3.1.x
215
236
 
216
237
  If something doesn't work on one of these versions, it's a bug.
217
238
 
@@ -231,11 +252,12 @@ dropped.
231
252
 
232
253
  This library aims to support work with following [Sidekiq][sidekiq] versions:
233
254
 
234
- * Sidekiq 5.0.x
235
- * Sidekiq 5.1.x
236
- * Sidekiq 5.2.x
237
255
  * Sidekiq 6.0.x
238
256
  * Sidekiq 6.1.x
257
+ * Sidekiq 6.2.x
258
+ * Sidekiq 6.3.x
259
+ * Sidekiq 6.4.x
260
+ * Sidekiq 6.5.x
239
261
 
240
262
 
241
263
  ## Contributing
@@ -261,11 +283,5 @@ bundle exec rubocop # run static code analysis
261
283
  Don't forget to run `appraisal update` after any changes to `Gemfile`.
262
284
 
263
285
 
264
- ## Copyright
265
-
266
- Copyright (c) 2015-2020 SensorTower Inc.
267
- See LICENSE.md for further details.
268
-
269
-
270
- [travis]: http://travis-ci.org/sensortower/sidekiq-throttled
286
+ [ci]: https://github.com/ixti/sidekiq-throttled/actions/workflows/ci.yml
271
287
  [sidekiq]: https://github.com/mperham/sidekiq
data/Rakefile CHANGED
@@ -24,4 +24,4 @@ end
24
24
  default_suite = ENV["CI"] ? :spec : %i[spec rubocop]
25
25
  named_suites = { "rubocop" => :rubocop, "rspec" => :spec }
26
26
 
27
- task :default => named_suites.fetch(ENV["SUITE"], default_suite)
27
+ task :default => named_suites.fetch(ENV.fetch("SUITE", nil), default_suite)
@@ -5,9 +5,6 @@ source "https://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "rake"
7
7
  gem "rspec"
8
- gem "rubocop", "~> 0.82.0", require: false
9
- gem "rubocop-performance", "~>1.5.2", require: false
10
- gem "rubocop-rspec", "~> 1.39.0", require: false
11
8
  gem "sidekiq", "~> 6.0.0"
12
9
 
13
10
  group :development do
@@ -20,12 +17,17 @@ end
20
17
  group :test do
21
18
  gem "apparition"
22
19
  gem "capybara"
23
- gem "coveralls", require: false
24
20
  gem "puma"
25
21
  gem "rack-test"
26
- gem "simplecov"
27
22
  gem "sinatra"
28
23
  gem "timecop"
29
24
  end
30
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
+
31
33
  gemspec path: "../"
@@ -5,9 +5,6 @@ source "https://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "rake"
7
7
  gem "rspec"
8
- gem "rubocop", "~> 0.82.0", require: false
9
- gem "rubocop-performance", "~>1.5.2", require: false
10
- gem "rubocop-rspec", "~> 1.39.0", require: false
11
8
  gem "sidekiq", "~> 6.1.0"
12
9
 
13
10
  group :development do
@@ -20,12 +17,17 @@ end
20
17
  group :test do
21
18
  gem "apparition"
22
19
  gem "capybara"
23
- gem "coveralls", require: false
24
20
  gem "puma"
25
21
  gem "rack-test"
26
- gem "simplecov"
27
22
  gem "sinatra"
28
23
  gem "timecop"
29
24
  end
30
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
+
31
33
  gemspec path: "../"
@@ -5,10 +5,7 @@ source "https://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "rake"
7
7
  gem "rspec"
8
- gem "rubocop", "~> 0.82.0", require: false
9
- gem "rubocop-performance", "~>1.5.2", require: false
10
- gem "rubocop-rspec", "~> 1.39.0", require: false
11
- gem "sidekiq", "~> 5.0.0"
8
+ gem "sidekiq", "~> 6.2.0"
12
9
 
13
10
  group :development do
14
11
  gem "byebug"
@@ -20,12 +17,17 @@ end
20
17
  group :test do
21
18
  gem "apparition"
22
19
  gem "capybara"
23
- gem "coveralls", require: false
24
20
  gem "puma"
25
21
  gem "rack-test"
26
- gem "simplecov"
27
22
  gem "sinatra"
28
23
  gem "timecop"
29
24
  end
30
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
+
31
33
  gemspec path: "../"