sidekiq-rate-limiter 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +48 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +19 -0
- data/README.md +2 -2
- data/gemfiles/sidekiq_6.0.gemfile +5 -0
- data/gemfiles/sidekiq_6.1.gemfile +5 -0
- data/gemfiles/sidekiq_6.x.gemfile +5 -0
- data/lib/sidekiq-rate-limiter/server.rb +8 -1
- data/lib/sidekiq-rate-limiter/version.rb +1 -1
- data/sidekiq-rate-limiter.gemspec +3 -3
- data/spec/sidekiq-rate-limiter/fetch_spec.rb +14 -2
- data/spec/sidekiq-rate-limiter/server_spec.rb +10 -2
- data/spec/spec_helper.rb +19 -41
- metadata +35 -15
- data/.simplecov +0 -6
- data/.travis.yml +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eaf0f64591b7ddcbba0d15b889fdfbe2b639cce8b112a8be3e92ec9cac2dc07e
|
4
|
+
data.tar.gz: fbfadc77f1bf676221b3e8c268a4ac60d4a19bc55e3a22a74c2084b9e62c3ee2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00bf480916d2764f62e2e96b377573bcfe266c05c95d8a395f5b1293c84d3122f11355fa311c9af019fc50b07ae4228c51e06e4ded5dcb571c040b158d5fb6b3
|
7
|
+
data.tar.gz: 2907155a2a62408dcb3e1e928669588bd269057215de35cbe41782ee130e514823ff9fdc618f6b132484151bf8ca652360b213c0eaf398fb20b0ff815e235570
|
@@ -0,0 +1,48 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ['3.1', '2.7']
|
15
|
+
sidekiq-version: ['4', '5', '6.0', '6.1', '6.x']
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v3
|
19
|
+
|
20
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
21
|
+
uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
|
25
|
+
- name: Install dependencies
|
26
|
+
run: bundle install --gemfile=gemfiles/sidekiq_${{ matrix.sidekiq-version }}.gemfile
|
27
|
+
|
28
|
+
- name: Start Redis
|
29
|
+
uses: supercharge/redis-github-action@1.5.0
|
30
|
+
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec --gemfile=gemfiles/sidekiq_${{ matrix.sidekiq-version }}.gemfile rspec
|
33
|
+
|
34
|
+
- name: Coveralls
|
35
|
+
uses: coverallsapp/github-action@v1
|
36
|
+
with:
|
37
|
+
flag-name: run-${{ join(matrix.*, '-') }}
|
38
|
+
parallel: true
|
39
|
+
|
40
|
+
finish:
|
41
|
+
needs: test
|
42
|
+
if: ${{ always() }}
|
43
|
+
runs-on: ubuntu-latest
|
44
|
+
steps:
|
45
|
+
- name: Coveralls Finished
|
46
|
+
uses: coverallsapp/github-action@v1
|
47
|
+
with:
|
48
|
+
parallel-finished: true
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
## 0.2.0 (Mar 1, 2023)
|
2
|
+
|
3
|
+
* Upstream fix for sidekiq 6.5.0 [#43, thanks to 5minpause]
|
4
|
+
* Add support for new Sidekiq's configuration model [#42, thanks to anero]
|
5
|
+
* gemspec: Drop defunct property rubyforge_project [#37, thanks to olleolleolle]
|
6
|
+
|
7
|
+
## 0.1.3 (Oct 15, 2019)
|
8
|
+
|
9
|
+
* Fix errors when using with redis-rb > 4.1.0 [#30, #31]
|
10
|
+
|
11
|
+
## 0.1.2 (Jul 5, 2018)
|
12
|
+
|
13
|
+
* Add (provisional) Sidekiq 5 support
|
14
|
+
|
15
|
+
## 0.1.1 (Feb 15, 2016)
|
16
|
+
|
17
|
+
* Add Sidekiq 4 support
|
18
|
+
* Drop Ruby 1.9 support
|
19
|
+
|
1
20
|
## 0.1.0 (May 30, 2014)
|
2
21
|
|
3
22
|
* Support callables for all configuration options
|
data/README.md
CHANGED
@@ -2,14 +2,14 @@ sidekiq-rate-limiter
|
|
2
2
|
====================
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/sidekiq-rate-limiter.svg)](https://rubygems.org/gems/sidekiq-rate-limiter)
|
5
|
-
[![
|
5
|
+
[![Test Status](https://github.com/enova/sidekiq-rate-limiter/actions/workflows/test.yml/badge.svg)](https://github.com/enova/sidekiq-rate-limiter/actions/workflows/test.yml)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/github/enova/sidekiq-rate-limiter/badge.svg?branch=master)](https://coveralls.io/github/enova/sidekiq-rate-limiter?branch=master)
|
7
7
|
|
8
8
|
Redis-backed, per-worker rate limits for job processing.
|
9
9
|
|
10
10
|
## Compatibility
|
11
11
|
|
12
|
-
sidekiq-rate-limiter is actively tested against MRI versions 2.
|
12
|
+
sidekiq-rate-limiter is actively tested against MRI versions 2.7 and 3.1.
|
13
13
|
|
14
14
|
sidekiq-rate-limiter works by using a custom fetch class, the class responsible
|
15
15
|
for pulling work from the queue stored in Redis. Consequently you'll want to be
|
@@ -2,5 +2,12 @@ require 'sidekiq-rate-limiter/version'
|
|
2
2
|
require 'sidekiq-rate-limiter/fetch'
|
3
3
|
|
4
4
|
Sidekiq.configure_server do |config|
|
5
|
-
Sidekiq.
|
5
|
+
# Backwards compatibility for Sidekiq < 6.1.0 (see https://github.com/mperham/sidekiq/pull/4602 for details)
|
6
|
+
if (Sidekiq::BasicFetch.respond_to?(:bulk_requeue))
|
7
|
+
Sidekiq.options[:fetch] = Sidekiq::RateLimiter::Fetch
|
8
|
+
elsif (Sidekiq::VERSION < '6.5.0') # Sidekiq config was redesigned in https://github.com/mperham/sidekiq/pull/5340
|
9
|
+
Sidekiq.options[:fetch] = Sidekiq::RateLimiter::Fetch.new(Sidekiq.options)
|
10
|
+
else
|
11
|
+
Sidekiq[:fetch] = Sidekiq::RateLimiter::Fetch.new(Sidekiq)
|
12
|
+
end
|
6
13
|
end
|
@@ -13,7 +13,6 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.homepage = "https://github.com/enova/sidekiq-rate-limiter"
|
14
14
|
s.summary = %q{Redis-backed, per-worker rate limits for job processing}
|
15
15
|
s.description = %q{Redis-backed, per-worker rate limits for job processing}
|
16
|
-
s.rubyforge_project = "nowarning"
|
17
16
|
|
18
17
|
s.files = `git ls-files`.split("\n")
|
19
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -24,8 +23,9 @@ Gem::Specification.new do |s|
|
|
24
23
|
s.add_development_dependency "pry-byebug"
|
25
24
|
s.add_development_dependency "rake"
|
26
25
|
s.add_development_dependency "rspec", '~> 3.4'
|
27
|
-
s.add_development_dependency "
|
26
|
+
s.add_development_dependency "simplecov"
|
27
|
+
s.add_development_dependency "simplecov-lcov", '~> 0.8.0'
|
28
28
|
|
29
|
-
s.add_dependency "sidekiq", ">= 4.0", "<
|
29
|
+
s.add_dependency "sidekiq", ">= 4.0", "< 7.0"
|
30
30
|
s.add_dependency "redis_rate_limiter"
|
31
31
|
end
|
@@ -27,7 +27,14 @@ RSpec.describe Sidekiq::RateLimiter::Fetch do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
let(:options)
|
30
|
+
let(:options) do
|
31
|
+
if Sidekiq::VERSION =~ /^(4|5|6\.[0-4])/
|
32
|
+
{ queues: [queue, another_queue, another_queue] }
|
33
|
+
else
|
34
|
+
Sidekiq.tap { |s| s[:queues] = [queue, another_queue, another_queue] }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
31
38
|
let(:queue) { 'basic' }
|
32
39
|
let(:another_queue) { 'some_other_queue' }
|
33
40
|
let(:args) { ['I am some args'] }
|
@@ -46,8 +53,13 @@ RSpec.describe Sidekiq::RateLimiter::Fetch do
|
|
46
53
|
else
|
47
54
|
Sidekiq::Fetcher::TIMEOUT
|
48
55
|
end
|
56
|
+
|
57
|
+
if Sidekiq::VERSION.start_with?('6.5.')
|
58
|
+
_timeout = { timeout: timeout}
|
59
|
+
timeout = _timeout
|
60
|
+
end
|
49
61
|
|
50
|
-
fetch = described_class.new options.merge(:strict => true)
|
62
|
+
fetch = described_class.new options.merge!(:strict => true)
|
51
63
|
expect(fetch.queues_cmd).to eql(["queue:#{queue}", "queue:#{another_queue}", timeout])
|
52
64
|
end
|
53
65
|
|
@@ -8,13 +8,21 @@ RSpec.describe Sidekiq::RateLimiter, 'server configuration' do
|
|
8
8
|
|
9
9
|
it 'should set Sidekiq.options[:fetch] as desired' do
|
10
10
|
Sidekiq.configure_server do |config|
|
11
|
-
|
11
|
+
if Sidekiq::VERSION =~ /^(4|5|6.0)/
|
12
|
+
expect(Sidekiq.options[:fetch]).to eql(Sidekiq::RateLimiter::Fetch)
|
13
|
+
else
|
14
|
+
expect(Sidekiq.options[:fetch]).to be_a(Sidekiq::RateLimiter::Fetch)
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
15
19
|
it 'should inherit from Sidekiq::BasicFetch' do
|
16
20
|
Sidekiq.configure_server do |config|
|
17
|
-
|
21
|
+
if Sidekiq::VERSION =~ /^(4|5|6.0)/
|
22
|
+
expect(Sidekiq.options[:fetch]).to be < Sidekiq::BasicFetch
|
23
|
+
else
|
24
|
+
expect(Sidekiq.options[:fetch].class.ancestors[1]).to be(Sidekiq::BasicFetch)
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
20
28
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,35 +1,11 @@
|
|
1
1
|
require 'sidekiq'
|
2
2
|
require 'sidekiq/testing'
|
3
|
-
|
4
|
-
## Confirming presence of redis server executable
|
5
|
-
abort "## `redis-server` not in path" if %x(which redis-server).empty?
|
6
|
-
redis_dir = "#{File.dirname(__FILE__)}/support/redis"
|
7
|
-
|
8
|
-
## Redis configuration
|
9
|
-
REDIS_CONFIG = <<-CONF
|
10
|
-
daemonize yes
|
11
|
-
pidfile #{redis_dir}/test.pid
|
12
|
-
port 6380
|
13
|
-
timeout 300
|
14
|
-
save 900 1
|
15
|
-
save 300 10
|
16
|
-
save 60 10000
|
17
|
-
dbfilename test.rdb
|
18
|
-
dir #{redis_dir}
|
19
|
-
loglevel warning
|
20
|
-
logfile stdout
|
21
|
-
databases 1
|
22
|
-
CONF
|
23
|
-
|
24
|
-
%x(echo '#{REDIS_CONFIG}' > #{redis_dir}/test.conf)
|
25
|
-
redis_command = "redis-server #{redis_dir}/test.conf"
|
26
|
-
%x[ #{redis_command} ]
|
27
|
-
##
|
3
|
+
require 'pry-byebug'
|
28
4
|
|
29
5
|
## Configuring sidekiq
|
30
6
|
options = {
|
31
7
|
logger: nil,
|
32
|
-
redis: { :
|
8
|
+
redis: { url: ENV.fetch('REDIS_URL', 'redis://localhost:6379/0') }
|
33
9
|
}
|
34
10
|
|
35
11
|
Sidekiq.configure_client do |config|
|
@@ -43,12 +19,27 @@ Sidekiq.configure_server do |config|
|
|
43
19
|
config.send("#{option}=", value)
|
44
20
|
end
|
45
21
|
end
|
46
|
-
##
|
47
22
|
|
23
|
+
|
24
|
+
## Code Coverage
|
48
25
|
require 'simplecov'
|
49
26
|
|
27
|
+
SimpleCov.start do
|
28
|
+
if ENV['CI']
|
29
|
+
require 'simplecov-lcov'
|
30
|
+
|
31
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
32
|
+
c.report_with_single_file = true
|
33
|
+
c.single_report_path = 'coverage/lcov.info'
|
34
|
+
end
|
35
|
+
|
36
|
+
formatter SimpleCov::Formatter::LcovFormatter
|
37
|
+
end
|
38
|
+
|
39
|
+
add_filter %w[version.rb spec/]
|
40
|
+
end
|
41
|
+
|
50
42
|
require File.expand_path("../../lib/sidekiq-rate-limiter", __FILE__)
|
51
|
-
##
|
52
43
|
|
53
44
|
## Hook to set Sidekiq::Testing mode using rspec tags
|
54
45
|
RSpec.configure do |config|
|
@@ -76,18 +67,5 @@ RSpec.configure do |config|
|
|
76
67
|
elsif Sidekiq::Testing.fake?
|
77
68
|
Sidekiq::Worker.clear_all
|
78
69
|
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
config.after(:all) do
|
83
|
-
## Stopping Redis
|
84
|
-
ps = %x(ps -A -o pid,command | grep '#{redis_command}' | grep -v grep).split($/)
|
85
|
-
pids = ps.map { |p| p.split(/\s+/).reject(&:empty?).first.to_i }
|
86
|
-
pids.each { |pid| Process.kill("TERM", pid) }
|
87
|
-
|
88
|
-
## Cleaning up
|
89
|
-
sleep 0.1
|
90
|
-
%x(rm -rf #{redis_dir}/*)
|
91
70
|
end
|
92
71
|
end
|
93
|
-
##
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-rate-limiter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Docady
|
8
8
|
- Blake Thomas
|
9
9
|
- Enova
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pry
|
@@ -69,19 +69,33 @@ dependencies:
|
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '3.4'
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
72
|
+
name: simplecov
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: simplecov-lcov
|
73
87
|
requirement: !ruby/object:Gem::Requirement
|
74
88
|
requirements:
|
75
89
|
- - "~>"
|
76
90
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
91
|
+
version: 0.8.0
|
78
92
|
type: :development
|
79
93
|
prerelease: false
|
80
94
|
version_requirements: !ruby/object:Gem::Requirement
|
81
95
|
requirements:
|
82
96
|
- - "~>"
|
83
97
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
98
|
+
version: 0.8.0
|
85
99
|
- !ruby/object:Gem::Dependency
|
86
100
|
name: sidekiq
|
87
101
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,7 +105,7 @@ dependencies:
|
|
91
105
|
version: '4.0'
|
92
106
|
- - "<"
|
93
107
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
108
|
+
version: '7.0'
|
95
109
|
type: :runtime
|
96
110
|
prerelease: false
|
97
111
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -101,7 +115,7 @@ dependencies:
|
|
101
115
|
version: '4.0'
|
102
116
|
- - "<"
|
103
117
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
118
|
+
version: '7.0'
|
105
119
|
- !ruby/object:Gem::Dependency
|
106
120
|
name: redis_rate_limiter
|
107
121
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,10 +137,10 @@ executables: []
|
|
123
137
|
extensions: []
|
124
138
|
extra_rdoc_files: []
|
125
139
|
files:
|
140
|
+
- ".github/workflows/test.yml"
|
126
141
|
- ".gitignore"
|
127
142
|
- ".rspec"
|
128
|
-
- ".
|
129
|
-
- ".travis.yml"
|
143
|
+
- ".ruby-version"
|
130
144
|
- CHANGELOG.md
|
131
145
|
- Gemfile
|
132
146
|
- LICENSE
|
@@ -134,6 +148,9 @@ files:
|
|
134
148
|
- Rakefile
|
135
149
|
- gemfiles/sidekiq_4.gemfile
|
136
150
|
- gemfiles/sidekiq_5.gemfile
|
151
|
+
- gemfiles/sidekiq_6.0.gemfile
|
152
|
+
- gemfiles/sidekiq_6.1.gemfile
|
153
|
+
- gemfiles/sidekiq_6.x.gemfile
|
137
154
|
- lib/sidekiq-rate-limiter.rb
|
138
155
|
- lib/sidekiq-rate-limiter/fetch.rb
|
139
156
|
- lib/sidekiq-rate-limiter/server.rb
|
@@ -147,7 +164,7 @@ homepage: https://github.com/enova/sidekiq-rate-limiter
|
|
147
164
|
licenses:
|
148
165
|
- MIT
|
149
166
|
metadata: {}
|
150
|
-
post_install_message:
|
167
|
+
post_install_message:
|
151
168
|
rdoc_options: []
|
152
169
|
require_paths:
|
153
170
|
- lib
|
@@ -162,9 +179,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
179
|
- !ruby/object:Gem::Version
|
163
180
|
version: '0'
|
164
181
|
requirements: []
|
165
|
-
|
166
|
-
|
167
|
-
signing_key:
|
182
|
+
rubygems_version: 3.1.6
|
183
|
+
signing_key:
|
168
184
|
specification_version: 4
|
169
185
|
summary: Redis-backed, per-worker rate limits for job processing
|
170
|
-
test_files:
|
186
|
+
test_files:
|
187
|
+
- spec/sidekiq-rate-limiter/fetch_spec.rb
|
188
|
+
- spec/sidekiq-rate-limiter/server_spec.rb
|
189
|
+
- spec/spec_helper.rb
|
190
|
+
- spec/support/redis/.keep
|
data/.simplecov
DELETED
data/.travis.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
sudo: false
|
4
|
-
rvm:
|
5
|
-
- 2.5.1
|
6
|
-
- 2.4.4
|
7
|
-
|
8
|
-
gemfile:
|
9
|
-
- 'gemfiles/sidekiq_4.gemfile'
|
10
|
-
- 'gemfiles/sidekiq_5.gemfile'
|
11
|
-
|
12
|
-
deploy:
|
13
|
-
provider: rubygems
|
14
|
-
api_key:
|
15
|
-
secure: "VX48kpd9UySMWSDMwjxaNZy14RW1usU7eFLGNeohjCzxUsCywn+mS5/IZHl56vDXWJp7JwnboDiIa74hGV86PcSEM7kr+DAZO33iCazMNTpoWDiH1iJfj0jZbO2rOvx0rGI9fGYcC9xfyKQ37hVb13Eo0bnKa0YX30HArnx7EFo="
|
16
|
-
on:
|
17
|
-
tags: true
|
18
|
-
all_branches: true
|