sidekiq-throttled 0.2.0 → 0.3.0.pre
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/.gitignore +1 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +3 -0
- data/Appraisals +8 -0
- data/CHANGES.md +7 -0
- data/Gemfile +4 -2
- data/gemfiles/sidekiq_3.gemfile +19 -0
- data/gemfiles/sidekiq_4.gemfile +18 -0
- data/lib/sidekiq/throttled/basic_fetch.rb +12 -6
- data/lib/sidekiq/throttled/strategy.rb +11 -10
- data/lib/sidekiq/throttled/version.rb +1 -1
- data/sidekiq-throttled.gemspec +1 -1
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ab882d56754f6c3919be0df6fcac0c28f8fd636
|
4
|
+
data.tar.gz: bf5faf08f5addaef7328c3e49f042f9fcfcd5579
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44411490a00f21cea8dffc48295d98055568d678431dbb6d1cf25da5d463017605c411aaf0252d7ebd9337f797d6fa5b759af3909ab8831aa402de3080ddc2a7
|
7
|
+
data.tar.gz: 477e5b5ce0fb9f72f2bc3815d58af655239f14ba7198321e3cb2800458a96d852fdca8c06d42d17bd86e197a68a616c26ea5b69b8ba7131ec7d603b15d9225ce
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
|
1
4
|
## Styles ######################################################################
|
2
5
|
|
3
6
|
Style/AlignParameters:
|
@@ -24,6 +27,9 @@ Style/FrozenStringLiteralComment:
|
|
24
27
|
Style/HashSyntax:
|
25
28
|
EnforcedStyle: hash_rockets
|
26
29
|
|
30
|
+
Style/IndentArray:
|
31
|
+
EnforcedStyle: consistent
|
32
|
+
|
27
33
|
Style/IndentHash:
|
28
34
|
EnforcedStyle: consistent
|
29
35
|
|
data/.travis.yml
CHANGED
data/Appraisals
ADDED
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
source "https://rubygems.org"
|
3
3
|
|
4
|
+
gem "appraisal"
|
5
|
+
gem "rspec"
|
6
|
+
gem "rubocop", "~> 0.39.0"
|
7
|
+
|
4
8
|
group :test do
|
5
9
|
gem "coveralls"
|
6
10
|
gem "rack-test"
|
7
|
-
gem "rspec"
|
8
|
-
gem "rubocop"
|
9
11
|
gem "simplecov", ">= 0.9"
|
10
12
|
gem "sinatra", "~> 1.4", ">= 1.4.6"
|
11
13
|
gem "timecop"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal"
|
6
|
+
gem "rspec"
|
7
|
+
gem "rubocop", "~> 0.39.0"
|
8
|
+
gem "celluloid"
|
9
|
+
gem "sidekiq", "~> 3.0"
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem "coveralls"
|
13
|
+
gem "rack-test"
|
14
|
+
gem "simplecov", ">= 0.9"
|
15
|
+
gem "sinatra", "~> 1.4", ">= 1.4.6"
|
16
|
+
gem "timecop"
|
17
|
+
end
|
18
|
+
|
19
|
+
gemspec :path => "../"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal"
|
6
|
+
gem "rspec"
|
7
|
+
gem "rubocop", "~> 0.39.0"
|
8
|
+
gem "sidekiq", "~> 4.0"
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem "coveralls"
|
12
|
+
gem "rack-test"
|
13
|
+
gem "simplecov", ">= 0.9"
|
14
|
+
gem "sinatra", "~> 1.4", ">= 1.4.6"
|
15
|
+
gem "timecop"
|
16
|
+
end
|
17
|
+
|
18
|
+
gemspec :path => "../"
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require "thread"
|
4
4
|
|
5
5
|
# 3rd party
|
6
|
-
require "celluloid"
|
6
|
+
require "celluloid" if Sidekiq::VERSION < "4.0.0"
|
7
7
|
require "sidekiq"
|
8
8
|
require "sidekiq/fetch"
|
9
9
|
|
@@ -11,6 +11,12 @@ module Sidekiq
|
|
11
11
|
module Throttled
|
12
12
|
# Throttled version of `Sidekiq::BasicFetch` fetcher strategy.
|
13
13
|
class BasicFetch < ::Sidekiq::BasicFetch
|
14
|
+
TIMEOUT = 2
|
15
|
+
|
16
|
+
class UnitOfWork < ::Sidekiq::BasicFetch::UnitOfWork
|
17
|
+
alias job message if Sidekiq::VERSION < "4.0.0"
|
18
|
+
end
|
19
|
+
|
14
20
|
# Class constructor
|
15
21
|
def initialize(*args)
|
16
22
|
@mutex = Mutex.new
|
@@ -24,13 +30,13 @@ module Sidekiq
|
|
24
30
|
work = brpop
|
25
31
|
return unless work
|
26
32
|
|
27
|
-
work =
|
28
|
-
return work unless Throttled.throttled? work.
|
33
|
+
work = UnitOfWork.new(*work)
|
34
|
+
return work unless Throttled.throttled? work.job
|
29
35
|
|
30
36
|
queue = "queue:#{work.queue_name}"
|
31
37
|
|
32
38
|
@mutex.synchronize { @suspended << queue }
|
33
|
-
Sidekiq.redis { |conn| conn.lpush(queue, work.
|
39
|
+
Sidekiq.redis { |conn| conn.lpush(queue, work.job) }
|
34
40
|
|
35
41
|
nil
|
36
42
|
end
|
@@ -53,11 +59,11 @@ module Sidekiq
|
|
53
59
|
end
|
54
60
|
|
55
61
|
if queues.empty?
|
56
|
-
sleep
|
62
|
+
sleep TIMEOUT
|
57
63
|
return
|
58
64
|
end
|
59
65
|
|
60
|
-
Sidekiq.redis { |conn| conn.brpop(*queues,
|
66
|
+
Sidekiq.redis { |conn| conn.brpop(*queues, TIMEOUT) }
|
61
67
|
end
|
62
68
|
end
|
63
69
|
end
|
@@ -25,16 +25,17 @@ module Sidekiq
|
|
25
25
|
def initialize(name, concurrency: nil, threshold: nil, key_suffix: nil)
|
26
26
|
key = "throttled:#{name}"
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
28
|
+
@concurrency =
|
29
|
+
if concurrency
|
30
|
+
concurrency[:key_suffix] = key_suffix
|
31
|
+
Concurrency.new(key, concurrency)
|
32
|
+
end
|
33
|
+
|
34
|
+
@threshold =
|
35
|
+
if threshold
|
36
|
+
threshold[:key_suffix] = key_suffix
|
37
|
+
Threshold.new(key, threshold)
|
38
|
+
end
|
38
39
|
|
39
40
|
return if @concurrency || @threshold
|
40
41
|
|
data/sidekiq-throttled.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
-
spec.add_runtime_dependency
|
28
|
+
spec.add_runtime_dependency "sidekiq"
|
29
29
|
|
30
30
|
spec.add_development_dependency "bundler", "~> 1.10"
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-throttled
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0.pre
|
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: 2016-
|
11
|
+
date: 2016-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,12 +64,15 @@ files:
|
|
64
64
|
- ".rubocop.yml"
|
65
65
|
- ".travis.yml"
|
66
66
|
- ".yardopts"
|
67
|
+
- Appraisals
|
67
68
|
- CHANGES.md
|
68
69
|
- Gemfile
|
69
70
|
- LICENSE.md
|
70
71
|
- README.md
|
71
72
|
- Rakefile
|
72
73
|
- bin/setup
|
74
|
+
- gemfiles/sidekiq_3.gemfile
|
75
|
+
- gemfiles/sidekiq_4.gemfile
|
73
76
|
- lib/sidekiq/throttled.rb
|
74
77
|
- lib/sidekiq/throttled/basic_fetch.rb
|
75
78
|
- lib/sidekiq/throttled/errors.rb
|
@@ -103,9 +106,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
106
|
version: '0'
|
104
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
108
|
requirements:
|
106
|
-
- - "
|
109
|
+
- - ">"
|
107
110
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
111
|
+
version: 1.3.1
|
109
112
|
requirements: []
|
110
113
|
rubyforge_project:
|
111
114
|
rubygems_version: 2.5.1
|