sidekiq-throttled 0.10.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +54 -0
  3. data/.rubocop/layout.yml +24 -0
  4. data/.rubocop/lint.yml +41 -0
  5. data/.rubocop/metrics.yml +4 -0
  6. data/.rubocop/performance.yml +25 -0
  7. data/.rubocop/rspec.yml +3 -0
  8. data/.rubocop/style.yml +84 -0
  9. data/.rubocop.yml +13 -68
  10. data/.rubocop_todo.yml +10 -35
  11. data/.travis.yml +2 -1
  12. data/Appraisals +8 -0
  13. data/CHANGES.md +28 -0
  14. data/Gemfile +6 -5
  15. data/LICENSE.md +1 -1
  16. data/README.md +75 -15
  17. data/gemfiles/sidekiq_5.0.gemfile +6 -5
  18. data/gemfiles/sidekiq_5.1.gemfile +6 -5
  19. data/gemfiles/sidekiq_5.2.gemfile +6 -5
  20. data/gemfiles/sidekiq_6.0.gemfile +31 -0
  21. data/gemfiles/sidekiq_6.1.gemfile +31 -0
  22. data/lib/sidekiq/throttled/communicator/callbacks.rb +7 -6
  23. data/lib/sidekiq/throttled/communicator/listener.rb +3 -3
  24. data/lib/sidekiq/throttled/expirable_list.rb +1 -1
  25. data/lib/sidekiq/throttled/fetch.rb +34 -20
  26. data/lib/sidekiq/throttled/queue_name.rb +1 -1
  27. data/lib/sidekiq/throttled/registry.rb +2 -5
  28. data/lib/sidekiq/throttled/strategy/concurrency.rb +5 -5
  29. data/lib/sidekiq/throttled/strategy/threshold.rb +6 -5
  30. data/lib/sidekiq/throttled/strategy.rb +23 -14
  31. data/lib/sidekiq/throttled/strategy_collection.rb +70 -0
  32. data/lib/sidekiq/throttled/utils.rb +1 -1
  33. data/lib/sidekiq/throttled/version.rb +1 -1
  34. data/lib/sidekiq/throttled/web/stats.rb +2 -6
  35. data/lib/sidekiq/throttled/web/summary_fix.rb +3 -2
  36. data/lib/sidekiq/throttled/web/throttled.html.erb +6 -2
  37. data/lib/sidekiq/throttled/web.rb +1 -1
  38. data/lib/sidekiq/throttled/worker.rb +2 -2
  39. data/lib/sidekiq/throttled.rb +14 -2
  40. data/sidekiq-throttled.gemspec +2 -0
  41. metadata +18 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a204bc340965b64fe16f9b896815c9b3fbf383418b0774871d90c35d4c8fb061
4
- data.tar.gz: bb2b9681a7caf33d3418ab2f475bc0ab2f6141ed9e6609d55d680815da71c4e6
3
+ metadata.gz: fe88fba2840a8a649b6a02951a246176e8b548257997aeaf922c7582e8c27e17
4
+ data.tar.gz: 76ba37d70509e33a266e7ad1e9e51babd4afd874788a1548b1aabc3a1c1cad87
5
5
  SHA512:
6
- metadata.gz: '0801102f967a02d3a023b9d8bfe04b8d44280c5f2986182ef4a5cc6e971091afcb3fb1b6c845f382829de071e11d6a3111cb04a21b040b022b61ecac76d5a422'
7
- data.tar.gz: 243ceeb9a791417edc07a7f697660035e52a61f3db4aefbe93508be5037d1af1932d2b3ad81886ee1b9ef8408e97f1bef8cac03b9a78d8e4c29a2197f9f927f6
6
+ metadata.gz: 14979e92d96a56096f19e61a40f8343025de2ccb4a57ede6f311be83acd80cca44d9bae7448ad2453e9539aa599c6154d2eec9f2a285148f14d2ad70fa9d86c4
7
+ data.tar.gz: 8ad7ee2999f8ab2645bdff54efc2b2592b5d416807795f58454af1a5f03ae3099975db492bbab4658cd2b9d5160af705c5509536c9dd7dddaa1db35c5ebe4448
@@ -0,0 +1,54 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ rspec:
11
+ name: "rspec (ruby:${{ matrix.ruby }} sidekiq:${{ matrix.sidekiq }})"
12
+
13
+ strategy:
14
+ matrix:
15
+ ruby: [ "2.6", "2.7" ]
16
+ sidekiq: [ "5.0", "5.1", "5.2", "6.0", "6.1" ]
17
+
18
+ runs-on: ubuntu-latest
19
+
20
+ services:
21
+ redis:
22
+ image: redis
23
+ ports: ["6379:6379"]
24
+ options: "--entrypoint redis-server"
25
+
26
+ env:
27
+ GEMFILE: gemfiles/sidekiq_${{ matrix.sidekiq }}.gemfile
28
+
29
+ steps:
30
+ - uses: actions/checkout@v2
31
+
32
+ - uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+
36
+ - name: bundle install
37
+ run: bundle install --without development --jobs 4 --retry 3
38
+
39
+ - run: bundle exec rspec
40
+
41
+ rubocop:
42
+ runs-on: ubuntu-latest
43
+
44
+ steps:
45
+ - uses: actions/checkout@v2
46
+
47
+ - uses: ruby/setup-ruby@v1
48
+ with:
49
+ ruby-version: "2.4"
50
+
51
+ - name: bundle install
52
+ run: bundle install --without development --jobs 4 --retry 3
53
+
54
+ - run: bundle exec rubocop
@@ -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
+
@@ -0,0 +1,3 @@
1
+ RSpec/ExampleLength:
2
+ Enabled: true
3
+ Max: 10
@@ -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
data/.rubocop.yml CHANGED
@@ -1,74 +1,19 @@
1
- inherit_from:
2
- - .rubocop_todo.yml
3
-
4
1
  require:
2
+ - rubocop-performance
5
3
  - rubocop-rspec
6
4
 
7
- ################################################################################
5
+ inherit_from:
6
+ - .rubocop_todo.yml
7
+ - .rubocop/layout.yml
8
+ - .rubocop/lint.yml
9
+ - .rubocop/metrics.yml
10
+ - .rubocop/performance.yml
11
+ - .rubocop/rspec.yml
12
+ - .rubocop/style.yml
8
13
 
9
14
  AllCops:
10
- DisplayCopNames: true
11
- TargetRubyVersion: 2.4
12
- Exclude:
13
- - "gemfiles/*"
14
-
15
- ## Layout ######################################################################
16
-
17
- Layout/AlignHash:
18
- EnforcedHashRocketStyle: table
19
-
20
- Layout/AlignParameters:
21
- EnforcedStyle: with_fixed_indentation
22
-
23
- Layout/IndentArray:
24
- EnforcedStyle: consistent
25
-
26
- Layout/IndentHash:
27
- EnforcedStyle: consistent
28
-
29
- Layout/MultilineMethodCallIndentation:
30
- EnforcedStyle: indented
31
-
32
- Layout/SpaceInLambdaLiteral:
33
- EnforcedStyle: require_space
34
-
35
- ## Metrics #####################################################################
36
-
37
- Metrics/BlockLength:
38
15
  Exclude:
39
- - "Guardfile"
40
- - "spec/**/*"
41
-
42
- ## Styles ######################################################################
43
-
44
- Style/BracesAroundHashParameters:
45
- Enabled: false
46
-
47
- Style/Documentation:
48
- Enabled: false
49
-
50
- Style/HashSyntax:
51
- EnforcedStyle: hash_rockets
52
-
53
- # Follow your heart where it makes sense to use lambda or lambda literal.
54
- # Enforcing it makes some pieces of code look REALLY terrible, e.g. in
55
- # case of empty (noop) lambdas: `lambda { |_| }`.
56
- Style/Lambda:
57
- Enabled: false
58
-
59
- # Enabling this cop makes Guardfile (which is full of pathname regexps)
60
- # look absolutley style-inconsistent and terrible. In any case, this should
61
- # be on developer's choice whenever to use `%r` or not. Just like we don't
62
- # enforce to use `["foo"]` over `%w(foo)` and so on.
63
- Style/RegexpLiteral:
64
- Enabled: false
65
-
66
- Style/RescueStandardError:
67
- EnforcedStyle: implicit
68
-
69
- Style/StringLiterals:
70
- EnforcedStyle: double_quotes
71
-
72
- # I prefer Yoda style instead, but there's no such enforcement style.
73
- Style/YodaCondition:
74
- Enabled: false
16
+ - gemfiles/**/*
17
+ - vendor/**/*
18
+ NewCops: enable
19
+ TargetRubyVersion: 2.4
data/.rubocop_todo.yml CHANGED
@@ -1,57 +1,32 @@
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 2020-09-14 13:53:26 UTC using RuboCop version 0.90.0.
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
13
-
14
- # Offense count: 25
15
- # Configuration parameters: Max.
16
- RSpec/ExampleLength:
17
- 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
- - 'spec/sidekiq/throttled/web/queues_spec.rb'
25
- - 'spec/sidekiq/throttled_spec.rb'
26
-
27
- # Offense count: 62
9
+ # Offense count: 68
28
10
  # Configuration parameters: .
29
11
  # SupportedStyles: have_received, receive
30
12
  RSpec/MessageSpies:
31
13
  EnforcedStyle: receive
32
14
 
33
- # Offense count: 20
34
- # Configuration parameters: AggregateFailuresByDefault.
15
+ # Offense count: 22
35
16
  RSpec/MultipleExpectations:
36
17
  Max: 4
37
18
 
38
- # Offense count: 33
19
+ # Offense count: 7
20
+ # Configuration parameters: AllowSubject.
21
+ RSpec/MultipleMemoizedHelpers:
22
+ Max: 6
23
+
24
+ # Offense count: 46
39
25
  RSpec/NestedGroups:
40
26
  Max: 5
41
27
 
42
- # Offense count: 3
28
+ # Offense count: 4
43
29
  RSpec/SubjectStub:
44
30
  Exclude:
45
31
  - 'spec/sidekiq/throttled/communicator_spec.rb'
46
32
  - 'spec/sidekiq/throttled/queues_pauser_spec.rb'
47
-
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:
56
- Exclude:
57
- - 'lib/sidekiq/throttled/communicator/listener.rb'
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  language: ruby
2
- sudo: false
3
2
 
4
3
  services:
5
4
  - redis-server
@@ -23,6 +22,7 @@ rvm:
23
22
  - 2.4
24
23
  - 2.5
25
24
  - 2.6
25
+ - 2.7
26
26
 
27
27
  matrix:
28
28
  fast_finish: true
@@ -36,3 +36,4 @@ gemfile:
36
36
  - gemfiles/sidekiq_5.0.gemfile
37
37
  - gemfiles/sidekiq_5.1.gemfile
38
38
  - gemfiles/sidekiq_5.2.gemfile
39
+ - gemfiles/sidekiq_6.0.gemfile
data/Appraisals CHANGED
@@ -11,3 +11,11 @@ end
11
11
  appraise "sidekiq-5.2" do
12
12
  gem "sidekiq", "~> 5.2.0"
13
13
  end
14
+
15
+ appraise "sidekiq-6.0" do
16
+ gem "sidekiq", "~> 6.0.0"
17
+ end
18
+
19
+ appraise "sidekiq-6.1" do
20
+ gem "sidekiq", "~> 6.1.0"
21
+ end
data/CHANGES.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## 0.13.0 (2020-07-28)
2
+
3
+ * [#85](https://github.com/sensortower/sidekiq-throttled/pull/85)
4
+ Add Sidekiq 6.1+ support.
5
+ ([@hmaack])
6
+
7
+ ## 0.12.0 (2020-06-22)
8
+
9
+ * [#80](https://github.com/sensortower/sidekiq-throttled/pull/80)
10
+ Allow override cooldown timeout of queues with throttled jobs.
11
+ ([@vaot])
12
+
13
+ * [#76](https://github.com/sensortower/sidekiq-throttled/pull/76)
14
+ Fix warnings on Ruby 2.7
15
+ ([@lenon])
16
+
17
+
18
+ ## 0.11.0 (2019-08-24)
19
+
20
+ * [#59](https://github.com/sensortower/sidekiq-throttled/pull/59)
21
+ Add throttling observer.
22
+ ([@ogins57])
23
+
24
+
1
25
  ## 0.10.0 (2019-06-22)
2
26
 
3
27
  * [#60](https://github.com/sensortower/sidekiq-throttled/pull/60)
@@ -193,3 +217,7 @@
193
217
  [@iporsut]: https://github.com/iporsut
194
218
  [@mstruve]: https://github.com/mstruve
195
219
  [@ziaulrehman40]: https://github.com/ziaulrehman40
220
+ [@ogins57]: https://github.com/ogins57
221
+ [@lenon]: https://github.com/lenon
222
+ [@vaot]: https://github.com/vaot
223
+ [@hmaack]: https://github.com/hmaack
data/Gemfile CHANGED
@@ -5,8 +5,9 @@ source "https://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "rake"
7
7
  gem "rspec"
8
- gem "rubocop", "~> 0.58.0", :require => false
9
- gem "rubocop-rspec", "~> 1.29.1", :require => false
8
+ gem "rubocop", "~> 0.90.0", :require => false
9
+ gem "rubocop-performance", "~> 1.8.0", :require => false
10
+ gem "rubocop-rspec", "~> 1.43.2", :require => false
10
11
  gem "sidekiq"
11
12
 
12
13
  group :development do
@@ -17,13 +18,13 @@ group :development do
17
18
  end
18
19
 
19
20
  group :test do
21
+ gem "apparition"
20
22
  gem "capybara"
21
23
  gem "coveralls", :require => false
22
- gem "poltergeist"
23
24
  gem "puma"
24
25
  gem "rack-test"
25
- gem "simplecov", ">= 0.9"
26
- gem "sinatra", "~> 1.4", ">= 1.4.6"
26
+ gem "simplecov"
27
+ gem "sinatra"
27
28
  gem "timecop"
28
29
  end
29
30
 
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2018 SensorTower Inc.
3
+ Copyright (c) 2015-2020 SensorTower Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # Sidekiq::Throttled
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/sidekiq-throttled.svg)](http://rubygems.org/gems/sidekiq-throttled)
4
- [![Build Status](https://travis-ci.org/sensortower/sidekiq-throttled.svg?branch=master)](https://travis-ci.org/sensortower/sidekiq-throttled)
5
- [![Code Climate](https://codeclimate.com/github/sensortower/sidekiq-throttled.svg?branch=master)](https://codeclimate.com/github/sensortower/sidekiq-throttled)
6
- [![Coverage Status](https://coveralls.io/repos/github/sensortower/sidekiq-throttled/badge.svg?branch=master)](https://coveralls.io/github/sensortower/sidekiq-throttled?branch=master)
7
- [![API Docs](http://inch-ci.org/github/sensortower/sidekiq-throttled.svg?branch=master)](http://inch-ci.org/github/sensortower/sidekiq-throttled)
3
+ [![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
+ [![API Docs](https://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/sidekiq-throttled)
8
9
 
9
10
  Concurrency and threshold throttling for [Sidekiq][sidekiq].
10
11
 
11
-
12
12
  ## Installation
13
13
 
14
14
  Add this line to your application's Gemfile:
@@ -36,6 +36,9 @@ require "sidekiq/throttled"
36
36
  Sidekiq::Throttled.setup!
37
37
  ```
38
38
 
39
+ Load order can be an issue if you are using other Sidekiq plugins and/or middleware.
40
+ To prevent any problems, add the `.setup!` call to the bottom of your init file.
41
+
39
42
  Once you've done that you can include `Sidekiq::Throttled::Worker` to your
40
43
  job classes and configure throttling:
41
44
 
@@ -46,12 +49,12 @@ class MyWorker
46
49
 
47
50
  sidekiq_options :queue => :my_queue
48
51
 
49
- sidekiq_throttle({
52
+ sidekiq_throttle(
50
53
  # Allow maximum 10 concurrent jobs of this class at a time.
51
54
  :concurrency => { :limit => 10 },
52
55
  # Allow maximum 1K jobs being processed within one hour window.
53
56
  :threshold => { :limit => 1_000, :period => 1.hour }
54
- })
57
+ )
55
58
 
56
59
  def perform
57
60
  # ...
@@ -59,6 +62,38 @@ class MyWorker
59
62
  end
60
63
  ```
61
64
 
65
+ ### Observer
66
+
67
+ You can specify an observer that will be called on throttling. To do so pass an
68
+ `:observer` option with callable object:
69
+
70
+ ``` ruby
71
+ class MyWorker
72
+ include Sidekiq::Worker
73
+ include Sidekiq::Throttled::Worker
74
+
75
+ MY_OBSERVER = lambda do |strategy, *args|
76
+ # do something
77
+ end
78
+
79
+ sidekiq_options :queue => :my_queue
80
+
81
+ sidekiq_throttle(
82
+ :concurrency => { :limit => 10 },
83
+ :threshold => { :limit => 100, :period => 1.hour }
84
+ :observer => MY_OBSERVER
85
+ )
86
+
87
+ def perform(*args)
88
+ # ...
89
+ end
90
+ end
91
+ ```
92
+
93
+ Observer will receive `strategy, *args` arguments, where `strategy` is a Symbol
94
+ `:concurrency` or `:threshold`, and `*args` are the arguments that were passed
95
+ to the job.
96
+
62
97
 
63
98
  ### Dynamic throttling
64
99
 
@@ -71,10 +106,10 @@ class MyWorker
71
106
 
72
107
  sidekiq_options :queue => :my_queue
73
108
 
74
- sidekiq_throttle({
109
+ sidekiq_throttle(
75
110
  # Allow maximum 10 concurrent jobs per user at a time.
76
111
  :concurrency => { :limit => 10, :key_suffix => -> (user_id) { user_id } }
77
- })
112
+ )
78
113
 
79
114
  def perform(user_id)
80
115
  # ...
@@ -93,7 +128,7 @@ class MyWorker
93
128
 
94
129
  sidekiq_options :queue => :my_queue
95
130
 
96
- sidekiq_throttle({
131
+ sidekiq_throttle(
97
132
  # Allow maximum 1000 concurrent jobs of this class at a time for VIPs and 10 for all other users.
98
133
  :concurrency => {
99
134
  :limit => ->(user_id) { User.vip?(user_id) ? 1_000 : 10 },
@@ -104,7 +139,7 @@ class MyWorker
104
139
  :limit => ->(user_id) { User.vip?(user_id) ? 1_000 : 10 },
105
140
  :period => ->(user_id) { User.vip?(user_id) ? 1.hour : 1.day },
106
141
  :key_suffix => ->(user_id) { User.vip?(user_id) ? "vip" : "std" }
107
- })
142
+ )
108
143
 
109
144
  def perform(user_id)
110
145
  # ...
@@ -112,6 +147,30 @@ class MyWorker
112
147
  end
113
148
  ```
114
149
 
150
+ You also can use several different keys to throttle one worker.
151
+
152
+ ``` ruby
153
+ class MyWorker
154
+ include Sidekiq::Worker
155
+ include Sidekiq::Throttled::Worker
156
+
157
+ sidekiq_options :queue => :my_queue
158
+
159
+ sidekiq_throttle(
160
+ # Allow maximum 10 concurrent jobs per project at a time and maximum 2 jobs per user
161
+ :concurrency => [
162
+ { :limit => 10, :key_suffix => -> (project_id, user_id) { project_id } },
163
+ { :limit => 2, :key_suffix => -> (project_id, user_id) { user_id } }
164
+ ]
165
+ # For :threshold it works the same
166
+ )
167
+
168
+ def perform(project_id, user_id)
169
+ # ...
170
+ end
171
+ end
172
+ ```
173
+
115
174
  **NB** Don't forget to specify `:key_suffix` and make it return different values
116
175
  if you are using dynamic limit/period options. Otherwise you risk getting into
117
176
  some trouble.
@@ -174,9 +233,8 @@ end
174
233
  This library aims to support and is [tested against][travis] the following Ruby
175
234
  versions:
176
235
 
177
- * Ruby 2.4.x
178
- * Ruby 2.5.x
179
236
  * Ruby 2.6.x
237
+ * Ruby 2.7.x
180
238
 
181
239
  If something doesn't work on one of these versions, it's a bug.
182
240
 
@@ -199,6 +257,8 @@ This library aims to support work with following [Sidekiq][sidekiq] versions:
199
257
  * Sidekiq 5.0.x
200
258
  * Sidekiq 5.1.x
201
259
  * Sidekiq 5.2.x
260
+ * Sidekiq 6.0.x
261
+ * Sidekiq 6.1.x
202
262
 
203
263
 
204
264
  ## Contributing
@@ -226,7 +286,7 @@ Don't forget to run `appraisal update` after any changes to `Gemfile`.
226
286
 
227
287
  ## Copyright
228
288
 
229
- Copyright (c) 2015-2018 SensorTower Inc.
289
+ Copyright (c) 2015-2020 SensorTower Inc.
230
290
  See LICENSE.md for further details.
231
291
 
232
292