sidekiq-throttled 0.16.1 → 0.16.2
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/README.md +30 -16
- data/lib/sidekiq/throttled/configuration.rb +4 -4
- data/lib/sidekiq/throttled/job.rb +20 -20
- data/lib/sidekiq/throttled/version.rb +1 -1
- data/lib/sidekiq/throttled.rb +13 -8
- 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: 8f13258e6221758892919e37d8d233b33b52f46d3e6ae4f61700f009f1bb0553
|
4
|
+
data.tar.gz: a50132e8af4521c5c2d4f8edc3bcdc8d823160bd7c7ad2980bce6c4b10a29087
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cb7186478fa6eced7c69086aee8b7ba626b504db5d2b594bd416a3ce24254d9670047216c92290cc023c578c8cb83ab4cce952f6dc568055ca00a7707b8ef27
|
7
|
+
data.tar.gz: 44d7b64362ef7fd1fbf97e588c3048f249610f6613d3517ad3aa8a78f31447c93dd52ee2fa9fde84f84dc602620c1fa78081e29d96e78c43f327527f683ac953
|
data/README.md
CHANGED
@@ -36,13 +36,13 @@ Sidekiq::Throttled.setup!
|
|
36
36
|
Load order can be an issue if you are using other Sidekiq plugins and/or middleware.
|
37
37
|
To prevent any problems, add the `.setup!` call to the bottom of your init file.
|
38
38
|
|
39
|
-
Once you've done that you can include `Sidekiq::Throttled::
|
39
|
+
Once you've done that you can include `Sidekiq::Throttled::Job` to your
|
40
40
|
job classes and configure throttling:
|
41
41
|
|
42
42
|
``` ruby
|
43
|
-
class
|
44
|
-
include Sidekiq::
|
45
|
-
include Sidekiq::Throttled::
|
43
|
+
class MyJob
|
44
|
+
include Sidekiq::Job
|
45
|
+
include Sidekiq::Throttled::Job
|
46
46
|
|
47
47
|
sidekiq_options :queue => :my_queue
|
48
48
|
|
@@ -59,15 +59,29 @@ class MyWorker
|
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
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:
|
65
|
+
|
66
|
+
``` ruby
|
67
|
+
class MyWorker
|
68
|
+
include Sidekiq::Worker
|
69
|
+
include Sidekiq::Throttled::Worker
|
70
|
+
|
71
|
+
# ...
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
|
62
76
|
### Observer
|
63
77
|
|
64
78
|
You can specify an observer that will be called on throttling. To do so pass an
|
65
79
|
`:observer` option with callable object:
|
66
80
|
|
67
81
|
``` ruby
|
68
|
-
class
|
69
|
-
include Sidekiq::
|
70
|
-
include Sidekiq::Throttled::
|
82
|
+
class MyJob
|
83
|
+
include Sidekiq::Job
|
84
|
+
include Sidekiq::Throttled::Job
|
71
85
|
|
72
86
|
MY_OBSERVER = lambda do |strategy, *args|
|
73
87
|
# do something
|
@@ -97,9 +111,9 @@ to the job.
|
|
97
111
|
You can throttle jobs dynamically with `:key_suffix` option:
|
98
112
|
|
99
113
|
``` ruby
|
100
|
-
class
|
101
|
-
include Sidekiq::
|
102
|
-
include Sidekiq::Throttled::
|
114
|
+
class MyJob
|
115
|
+
include Sidekiq::Job
|
116
|
+
include Sidekiq::Throttled::Job
|
103
117
|
|
104
118
|
sidekiq_options :queue => :my_queue
|
105
119
|
|
@@ -119,9 +133,9 @@ for these values. The proc will be evaluated at the time the job is fetched
|
|
119
133
|
and will receive the same arguments that are passed to the job.
|
120
134
|
|
121
135
|
``` ruby
|
122
|
-
class
|
123
|
-
include Sidekiq::
|
124
|
-
include Sidekiq::Throttled::
|
136
|
+
class MyJob
|
137
|
+
include Sidekiq::Job
|
138
|
+
include Sidekiq::Throttled::Job
|
125
139
|
|
126
140
|
sidekiq_options :queue => :my_queue
|
127
141
|
|
@@ -147,9 +161,9 @@ end
|
|
147
161
|
You also can use several different keys to throttle one worker.
|
148
162
|
|
149
163
|
``` ruby
|
150
|
-
class
|
151
|
-
include Sidekiq::
|
152
|
-
include Sidekiq::Throttled::
|
164
|
+
class MyJob
|
165
|
+
include Sidekiq::Job
|
166
|
+
include Sidekiq::Throttled::Job
|
153
167
|
|
154
168
|
sidekiq_options :queue => :my_queue
|
155
169
|
|
@@ -21,14 +21,14 @@ module Sidekiq
|
|
21
21
|
# Instructs throttler to lookup strategies in parent classes, if there's
|
22
22
|
# no own strategy:
|
23
23
|
#
|
24
|
-
# class
|
25
|
-
# include Sidekiq::
|
26
|
-
# include Sidekiq::
|
24
|
+
# class FooJob
|
25
|
+
# include Sidekiq::Job
|
26
|
+
# include Sidekiq::Throttled::Job
|
27
27
|
#
|
28
28
|
# sidekiq_throttle :concurrency => { :limit => 42 }
|
29
29
|
# end
|
30
30
|
#
|
31
|
-
# class
|
31
|
+
# class BarJob < FooJob
|
32
32
|
# end
|
33
33
|
#
|
34
34
|
# By default in the example above, `Bar` won't have throttling options.
|
@@ -9,9 +9,9 @@ module Sidekiq
|
|
9
9
|
#
|
10
10
|
# @example Usage
|
11
11
|
#
|
12
|
-
# class
|
13
|
-
# include Sidekiq::
|
14
|
-
# include Sidekiq::Throttled::
|
12
|
+
# class MyJob
|
13
|
+
# include Sidekiq::Job
|
14
|
+
# include Sidekiq::Throttled::Job
|
15
15
|
#
|
16
16
|
# sidkiq_options :queue => :my_queue
|
17
17
|
# sidekiq_throttle :threshold => { :limit => 123, :period => 1.hour }
|
@@ -26,7 +26,7 @@ module Sidekiq
|
|
26
26
|
# Extends worker class with {ClassMethods}.
|
27
27
|
#
|
28
28
|
# @note Using `included` hook with extending worker with {ClassMethods}
|
29
|
-
# in order to make API inline with `include Sidekiq::
|
29
|
+
# in order to make API inline with `include Sidekiq::Job`.
|
30
30
|
#
|
31
31
|
# @private
|
32
32
|
def self.included(worker)
|
@@ -37,33 +37,33 @@ module Sidekiq
|
|
37
37
|
module ClassMethods
|
38
38
|
# Registers some strategy for the worker.
|
39
39
|
#
|
40
|
-
# @example Allow max 123
|
40
|
+
# @example Allow max 123 MyJob jobs per hour
|
41
41
|
#
|
42
|
-
# class
|
43
|
-
# include Sidekiq::
|
44
|
-
# include Sidekiq::Throttled::
|
42
|
+
# class MyJob
|
43
|
+
# include Sidekiq::Job
|
44
|
+
# include Sidekiq::Throttled::Job
|
45
45
|
#
|
46
46
|
# sidekiq_throttle({
|
47
47
|
# :threshold => { :limit => 123, :period => 1.hour }
|
48
48
|
# })
|
49
49
|
# end
|
50
50
|
#
|
51
|
-
# @example Allow max 10 concurrently running
|
51
|
+
# @example Allow max 10 concurrently running MyJob jobs
|
52
52
|
#
|
53
|
-
# class
|
54
|
-
# include Sidekiq::
|
55
|
-
# include Sidekiq::Throttled::
|
53
|
+
# class MyJob
|
54
|
+
# include Sidekiq::Job
|
55
|
+
# include Sidekiq::Throttled::Job
|
56
56
|
#
|
57
57
|
# sidekiq_throttle({
|
58
58
|
# :concurrency => { :limit => 10 }
|
59
59
|
# })
|
60
60
|
# end
|
61
61
|
#
|
62
|
-
# @example Allow max 10 concurrent
|
62
|
+
# @example Allow max 10 concurrent MyJob jobs and max 123 per hour
|
63
63
|
#
|
64
|
-
# class
|
65
|
-
# include Sidekiq::
|
66
|
-
# include Sidekiq::Throttled::
|
64
|
+
# class MyJob
|
65
|
+
# include Sidekiq::Job
|
66
|
+
# include Sidekiq::Throttled::Job
|
67
67
|
#
|
68
68
|
# sidekiq_throttle({
|
69
69
|
# :threshold => { :limit => 123, :period => 1.hour },
|
@@ -91,15 +91,15 @@ module Sidekiq
|
|
91
91
|
# Now we can assign it to our workers:
|
92
92
|
#
|
93
93
|
# class FetchProfileJob
|
94
|
-
# include Sidekiq::
|
95
|
-
# include Sidekiq::Throttled::
|
94
|
+
# include Sidekiq::Job
|
95
|
+
# include Sidekiq::Throttled::Job
|
96
96
|
#
|
97
97
|
# sidekiq_throttle_as :google_api
|
98
98
|
# end
|
99
99
|
#
|
100
100
|
# class FetchCommentsJob
|
101
|
-
# include Sidekiq::
|
102
|
-
# include Sidekiq::Throttled::
|
101
|
+
# include Sidekiq::Job
|
102
|
+
# include Sidekiq::Throttled::Job
|
103
103
|
#
|
104
104
|
# sidekiq_throttle_as :google_api
|
105
105
|
# end
|
data/lib/sidekiq/throttled.rb
CHANGED
@@ -22,12 +22,12 @@ module Sidekiq
|
|
22
22
|
# require "sidekiq/throttled"
|
23
23
|
# Sidekiq::Throttled.setup!
|
24
24
|
#
|
25
|
-
# Once you've done that you can include {Sidekiq::Throttled::
|
25
|
+
# Once you've done that you can include {Sidekiq::Throttled::Job} to your
|
26
26
|
# job classes and configure throttling:
|
27
27
|
#
|
28
|
-
# class
|
29
|
-
# include Sidekiq::
|
30
|
-
# include Sidekiq::Throttled::
|
28
|
+
# class MyJob
|
29
|
+
# include Sidekiq::Job
|
30
|
+
# include Sidekiq::Throttled::Job
|
31
31
|
#
|
32
32
|
# sidekiq_options :queue => :my_queue
|
33
33
|
#
|
@@ -62,7 +62,7 @@ module Sidekiq
|
|
62
62
|
QueuesPauser.instance.setup!
|
63
63
|
|
64
64
|
Sidekiq.configure_server do |config|
|
65
|
-
setup_strategy!
|
65
|
+
setup_strategy!(config)
|
66
66
|
|
67
67
|
require "sidekiq/throttled/middleware"
|
68
68
|
config.server_middleware do |chain|
|
@@ -94,15 +94,20 @@ module Sidekiq
|
|
94
94
|
private
|
95
95
|
|
96
96
|
# @return [void]
|
97
|
-
def setup_strategy!
|
97
|
+
def setup_strategy!(sidekiq_config)
|
98
98
|
require "sidekiq/throttled/fetch"
|
99
99
|
|
100
|
+
sidekiq_version = Gem::Version.new(Sidekiq::VERSION)
|
101
|
+
|
102
|
+
# https://github.com/mperham/sidekiq/commit/67daa7a408b214d593100f782271ed108686c147
|
103
|
+
sidekiq_config = sidekiq_config.options if sidekiq_version < Gem::Version.new("6.5.0")
|
104
|
+
|
100
105
|
# https://github.com/mperham/sidekiq/commit/fce05c9d4b4c0411c982078a4cf3a63f20f739bc
|
101
|
-
|
106
|
+
sidekiq_config[:fetch] =
|
102
107
|
if Gem::Version.new(Sidekiq::VERSION) < Gem::Version.new("6.1.0")
|
103
108
|
Sidekiq::Throttled::Fetch
|
104
109
|
else
|
105
|
-
Sidekiq::Throttled::Fetch.new(
|
110
|
+
Sidekiq::Throttled::Fetch.new(sidekiq_config)
|
106
111
|
end
|
107
112
|
end
|
108
113
|
|
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.16.
|
4
|
+
version: 0.16.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Zapparov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|