sidekiq-rate-limiter 0.1.2 → 0.1.3
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/.travis.yml +3 -5
- data/README.md +23 -22
- data/gemfiles/{sidekiq_2.gemfile → sidekiq_5.gemfile} +1 -1
- data/lib/sidekiq-rate-limiter/fetch.rb +2 -3
- data/lib/sidekiq-rate-limiter/version.rb +1 -1
- data/sidekiq-rate-limiter.gemspec +1 -1
- metadata +5 -6
- data/gemfiles/sidekiq_3.gemfile +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6a789f11daae2a1ae0f8d876c9a87e4245ba2604b22f6c980afbcb640127b61
|
4
|
+
data.tar.gz: 6525e4db367acc2bed4d215c6fce4f525e6432801761efdb44f6e03fb282a17f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2277e1beeaa770bf971a22763ab7c0eb6bbd4fdb2e331bd65af5dba09df138e7c4b7ecc2fc91bfe3ef45e5dd4b06495db7edbfe41202664f72e78c64fac004bd
|
7
|
+
data.tar.gz: 9c23eee484ea10a10ccffec8bf733b9c6cfdbdca003158fb803e6a9fdfc703dc4bfcc489ad27967aaa5b2b08f5788ffa4c8c63a0fc21d624ab1681ec94eacc32
|
data/.travis.yml
CHANGED
@@ -2,14 +2,12 @@ language: ruby
|
|
2
2
|
cache: bundler
|
3
3
|
sudo: false
|
4
4
|
rvm:
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.1.8
|
5
|
+
- 2.5.1
|
6
|
+
- 2.4.4
|
8
7
|
|
9
8
|
gemfile:
|
10
|
-
- 'gemfiles/sidekiq_2.gemfile'
|
11
|
-
- 'gemfiles/sidekiq_3.gemfile'
|
12
9
|
- 'gemfiles/sidekiq_4.gemfile'
|
10
|
+
- 'gemfiles/sidekiq_5.gemfile'
|
13
11
|
|
14
12
|
deploy:
|
15
13
|
provider: rubygems
|
data/README.md
CHANGED
@@ -4,16 +4,15 @@ sidekiq-rate-limiter
|
|
4
4
|
[](https://rubygems.org/gems/sidekiq-rate-limiter)
|
5
5
|
[](http://travis-ci.org/enova/sidekiq-rate-limiter)
|
6
6
|
[](https://coveralls.io/github/enova/sidekiq-rate-limiter?branch=master)
|
7
|
-
[](https://gemnasium.com/enova/sidekiq-rate-limiter)
|
8
7
|
|
9
8
|
Redis-backed, per-worker rate limits for job processing.
|
10
9
|
|
11
10
|
## Compatibility
|
12
11
|
|
13
|
-
sidekiq-rate-limiter is actively tested against MRI versions 2.
|
12
|
+
sidekiq-rate-limiter is actively tested against MRI versions 2.4 and 2.5.
|
14
13
|
|
15
14
|
sidekiq-rate-limiter works by using a custom fetch class, the class responsible
|
16
|
-
for pulling work from the queue stored in
|
15
|
+
for pulling work from the queue stored in Redis. Consequently you'll want to be
|
17
16
|
careful about using other gems that use a same strategy, [sidekiq-priority](https://github.com/socialpandas/sidekiq-priority)
|
18
17
|
being one example.
|
19
18
|
|
@@ -32,7 +31,7 @@ class MyWorker
|
|
32
31
|
end
|
33
32
|
```
|
34
33
|
|
35
|
-
Then you wouldn't need to change anything.
|
34
|
+
Then you wouldn't need to change anything.
|
36
35
|
|
37
36
|
## Installation
|
38
37
|
|
@@ -60,12 +59,14 @@ require 'sidekiq-rate-limiter/server'
|
|
60
59
|
|
61
60
|
Or, if you prefer, amend your Gemfile like so:
|
62
61
|
|
63
|
-
|
62
|
+
```ruby
|
63
|
+
gem 'sidekiq-rate-limiter', require: 'sidekiq-rate-limiter/server'
|
64
|
+
```
|
64
65
|
|
65
|
-
By default the limiter uses the name
|
66
|
-
constant
|
67
|
-
change this. Alternatively, you can include a
|
68
|
-
hash included in sidekiq_options
|
66
|
+
By default the limiter uses the name `sidekiq-rate-limiter`. You can define the
|
67
|
+
constant `Sidekiq::RateLimiter::DEFAULT_LIMIT_NAME` prior to requiring to
|
68
|
+
change this. Alternatively, you can include a `name` parameter in the configuration
|
69
|
+
hash included in `sidekiq_options`
|
69
70
|
|
70
71
|
For example, the following:
|
71
72
|
|
@@ -73,11 +74,11 @@ For example, the following:
|
|
73
74
|
class Job
|
74
75
|
include Sidekiq::Worker
|
75
76
|
|
76
|
-
sidekiq_options :
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
77
|
+
sidekiq_options queue: 'some_silly_queue',
|
78
|
+
rate: {
|
79
|
+
name: 'my_super_awesome_rate_limit',
|
80
|
+
limit: 50,
|
81
|
+
period: 3600, ## An hour
|
81
82
|
}
|
82
83
|
|
83
84
|
def perform(*args)
|
@@ -86,7 +87,7 @@ For example, the following:
|
|
86
87
|
```
|
87
88
|
|
88
89
|
The configuration above would result in any jobs beyond the first 50 in a one
|
89
|
-
hour period being delayed. The server will continue to fetch items from
|
90
|
+
hour period being delayed. The server will continue to fetch items from Redis, &
|
90
91
|
will place any items that are beyond the threshold at the back of their queue.
|
91
92
|
|
92
93
|
### Dynamic Configuration
|
@@ -99,11 +100,11 @@ The `Proc` may receive as its arguments the same values that will be passed to `
|
|
99
100
|
class Job
|
100
101
|
include Sidekiq::Worker
|
101
102
|
|
102
|
-
sidekiq_options :
|
103
|
-
:
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
103
|
+
sidekiq_options queue: "my_queue",1
|
104
|
+
rate: {
|
105
|
+
name: ->(user_id, rate_limit) { user_id },
|
106
|
+
limit: ->(user_id, rate_limit) { rate_limit },
|
107
|
+
period: ->{ Date.today.monday? ? 2.hours : 4.hours }, # can ignore arguments
|
107
108
|
}
|
108
109
|
|
109
110
|
def perform(user_id, rate_limit)
|
@@ -120,9 +121,9 @@ limited multiple times are counted as 'processed' each time, so the stats balloo
|
|
120
121
|
|
121
122
|
## TODO
|
122
123
|
|
123
|
-
* While it subclasses instead of monkey patching, setting Sidekiq.options[:fetch]
|
124
|
+
* While it subclasses instead of monkey patching, setting `Sidekiq.options[:fetch]`
|
124
125
|
is still asking for interaction issues. It would be better for this to be directly
|
125
|
-
in
|
126
|
+
in Sidekiq or to use some other means to accomplish this goal.
|
126
127
|
|
127
128
|
## Contributing
|
128
129
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'sidekiq'
|
2
|
-
require 'celluloid' if Sidekiq::VERSION < "4"
|
3
2
|
require 'sidekiq/fetch'
|
4
3
|
require 'redis_rate_limiter'
|
5
4
|
|
@@ -27,7 +26,7 @@ module Sidekiq::RateLimiter
|
|
27
26
|
|
28
27
|
options = {
|
29
28
|
:limit => (limit.respond_to?(:call) ? limit.call(*args) : limit).to_i,
|
30
|
-
:interval => (interval.respond_to?(:call) ? interval.call(*args) : interval).
|
29
|
+
:interval => (interval.respond_to?(:call) ? interval.call(*args) : interval).to_i,
|
31
30
|
:name => (name.respond_to?(:call) ? name.call(*args) : name).to_s,
|
32
31
|
}
|
33
32
|
|
@@ -90,7 +89,7 @@ module Sidekiq::RateLimiter
|
|
90
89
|
worker_class = @message['class']
|
91
90
|
options = Object.const_get(worker_class).get_sidekiq_options rescue {}
|
92
91
|
server_rate = options['rate'] || options['throttle'] || {}
|
93
|
-
@server_rate = server_rate.
|
92
|
+
@server_rate = server_rate.map { |k, v| [k.to_s, v] }.to_h
|
94
93
|
end
|
95
94
|
end
|
96
95
|
|
@@ -26,6 +26,6 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency "rspec", '~> 3.4'
|
27
27
|
s.add_development_dependency "coveralls", '~> 0.8'
|
28
28
|
|
29
|
-
s.add_dependency "sidekiq", ">=
|
29
|
+
s.add_dependency "sidekiq", ">= 4.0", "< 6.0"
|
30
30
|
s.add_dependency "redis_rate_limiter"
|
31
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-rate-limiter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Docady
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pry
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
requirements:
|
89
89
|
- - ">="
|
90
90
|
- !ruby/object:Gem::Version
|
91
|
-
version: '
|
91
|
+
version: '4.0'
|
92
92
|
- - "<"
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '6.0'
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
requirements:
|
99
99
|
- - ">="
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version: '
|
101
|
+
version: '4.0'
|
102
102
|
- - "<"
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '6.0'
|
@@ -132,9 +132,8 @@ files:
|
|
132
132
|
- LICENSE
|
133
133
|
- README.md
|
134
134
|
- Rakefile
|
135
|
-
- gemfiles/sidekiq_2.gemfile
|
136
|
-
- gemfiles/sidekiq_3.gemfile
|
137
135
|
- gemfiles/sidekiq_4.gemfile
|
136
|
+
- gemfiles/sidekiq_5.gemfile
|
138
137
|
- lib/sidekiq-rate-limiter.rb
|
139
138
|
- lib/sidekiq-rate-limiter/fetch.rb
|
140
139
|
- lib/sidekiq-rate-limiter/server.rb
|