sidekiq-throttled 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -0
- data/README.md +32 -0
- data/lib/sidekiq/throttled/strategy.rb +29 -15
- data/lib/sidekiq/throttled/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '05945dcd1de433dd74010e8fa402c6fb2e6100fb6306aef386536da24cd2e08b'
|
4
|
+
data.tar.gz: fe07b3c6409e7749f2af3b85d36e27dcda5d53b92c771e050a951f6175cec407
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2965642d0564eaf45c033b6c6d6ddfe5b80804eebfbfef7908c4f81bbc450baec4e71d1b70fe21bf6515336d173b3a95e74c4b97aa26d35a3947b7b24ba02c1e
|
7
|
+
data.tar.gz: 149ba3f6d29c9963c52f96d7ea1b6be23424726a7791afe7c3fad4ab95bf82b2db0df274ee3a26842e7726e1f403afff2d99c997f1033f2ddb63a95f9790d698
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.11.0 (2019-08-24)
|
2
|
+
|
3
|
+
* [#59](https://github.com/sensortower/sidekiq-throttled/pull/59)
|
4
|
+
Add throttling observer.
|
5
|
+
([@ogins57])
|
6
|
+
|
7
|
+
|
1
8
|
## 0.10.0 (2019-06-22)
|
2
9
|
|
3
10
|
* [#60](https://github.com/sensortower/sidekiq-throttled/pull/60)
|
@@ -193,3 +200,4 @@
|
|
193
200
|
[@iporsut]: https://github.com/iporsut
|
194
201
|
[@mstruve]: https://github.com/mstruve
|
195
202
|
[@ziaulrehman40]: https://github.com/ziaulrehman40
|
203
|
+
[@ogins57]: https://github.com/ogins57
|
data/README.md
CHANGED
@@ -59,6 +59,38 @@ class MyWorker
|
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
62
|
+
### Observer
|
63
|
+
|
64
|
+
You can specify an observer that will be called on throttling. To do so pass an
|
65
|
+
`:observer` option with callable object:
|
66
|
+
|
67
|
+
``` ruby
|
68
|
+
class MyWorker
|
69
|
+
include Sidekiq::Worker
|
70
|
+
include Sidekiq::Throttled::Worker
|
71
|
+
|
72
|
+
MY_OBSERVER = lambda do |strategy, *args|
|
73
|
+
# do something
|
74
|
+
end
|
75
|
+
|
76
|
+
sidekiq_options :queue => :my_queue
|
77
|
+
|
78
|
+
sidekiq_throttle({
|
79
|
+
:concurrency => { :limit => 10 },
|
80
|
+
:threshold => { :limit => 100, :period => 1.hour }
|
81
|
+
:observer => MY_OBSERVER
|
82
|
+
})
|
83
|
+
|
84
|
+
def perform(*args)
|
85
|
+
# ...
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
Observer will receive `strategy, *args` arguments, where `strategy` is a Symbol
|
91
|
+
`:concurrency` or `:threshold`, and `*args` are the arguements that were passed
|
92
|
+
to the job.
|
93
|
+
|
62
94
|
|
63
95
|
### Dynamic throttling
|
64
96
|
|
@@ -19,26 +19,24 @@ module Sidekiq
|
|
19
19
|
# @return [Strategy::Threshold, nil]
|
20
20
|
attr_reader :threshold
|
21
21
|
|
22
|
+
# @!attribute [r] observer
|
23
|
+
# @return [Proc, nil]
|
24
|
+
attr_reader :observer
|
25
|
+
|
22
26
|
# @param [#to_s] name
|
23
27
|
# @param [Hash] concurrency Concurrency options.
|
24
28
|
# See keyword args of {Strategy::Concurrency#initialize} for details.
|
25
29
|
# @param [Hash] threshold Threshold options.
|
26
30
|
# See keyword args of {Strategy::Threshold#initialize} for details.
|
27
31
|
# @param [#call] key_suffix Dynamic key suffix generator.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@threshold =
|
38
|
-
if threshold
|
39
|
-
threshold[:key_suffix] ||= key_suffix
|
40
|
-
Threshold.new(key, **threshold)
|
41
|
-
end
|
32
|
+
# @param [#call] observer Process called after throttled.
|
33
|
+
def initialize(
|
34
|
+
name,
|
35
|
+
concurrency: nil, threshold: nil, key_suffix: nil, observer: nil
|
36
|
+
)
|
37
|
+
@observer = observer
|
38
|
+
@concurrency = make_strategy(Concurrency, name, key_suffix, concurrency)
|
39
|
+
@threshold = make_strategy(Threshold, name, key_suffix, threshold)
|
42
40
|
|
43
41
|
return if @concurrency || @threshold
|
44
42
|
|
@@ -55,9 +53,13 @@ module Sidekiq
|
|
55
53
|
|
56
54
|
# @return [Boolean] whenever job is throttled or not.
|
57
55
|
def throttled?(jid, *job_args)
|
58
|
-
|
56
|
+
if @concurrency&.throttled?(jid, *job_args)
|
57
|
+
@observer&.call(:concurrency, *job_args)
|
58
|
+
return true
|
59
|
+
end
|
59
60
|
|
60
61
|
if @threshold&.throttled?(*job_args)
|
62
|
+
@observer&.call(:threshold, *job_args)
|
61
63
|
finalize!(jid, *job_args)
|
62
64
|
return true
|
63
65
|
end
|
@@ -77,6 +79,18 @@ module Sidekiq
|
|
77
79
|
@concurrency&.reset!
|
78
80
|
@threshold&.reset!
|
79
81
|
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
# @return [Base, nil]
|
86
|
+
def make_strategy(strategy, name, key_suffix, options)
|
87
|
+
return unless options
|
88
|
+
|
89
|
+
strategy.new("throttled:#{name}", {
|
90
|
+
:key_suffix => key_suffix,
|
91
|
+
**options
|
92
|
+
})
|
93
|
+
end
|
80
94
|
end
|
81
95
|
end
|
82
96
|
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.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey V Zapparov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|