sidekiq-throttled 0.4.1 → 0.5.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/.travis.yml +0 -1
- data/Appraisals +0 -5
- data/CHANGES.md +3 -4
- data/README.md +16 -6
- data/lib/sidekiq/throttled.rb +2 -2
- data/lib/sidekiq/throttled/{basic_fetch.rb → fetch.rb} +13 -14
- data/lib/sidekiq/throttled/unit_of_work.rb +33 -0
- data/lib/sidekiq/throttled/version.rb +1 -1
- data/lib/sidekiq/throttled/web/index.html.erb +1 -1
- metadata +3 -3
- data/gemfiles/sidekiq_3.x.gemfile +0 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 427e3b20c7b521948d64ca4d6845c660eaebf278
|
|
4
|
+
data.tar.gz: 25ccc08885012c0f7269651399d117d1bca07c9c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8d5aa36914a6c4a69f6b644defd5c97a34ca38d04c59707b4b74a58d559911509599e51428670d875c1b4a8aef10e8d944be51cdaafbb9b0196cab7ac9b9250
|
|
7
|
+
data.tar.gz: 06af7fc7818f88df36c017e92c1033429ad782ab3a0c11eb698b531d649efb7cbb294f1e1865bbaa8eb33de4c023a393f6429edca75d4806f4c501ade2a37b21
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
data/CHANGES.md
CHANGED
data/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Sidekiq::Throttled
|
|
2
2
|
|
|
3
|
-
[](http://rubygems.org/gems/sidekiq-throttled)
|
|
4
|
+
[](https://travis-ci.org/sensortower/sidekiq-throttled)
|
|
5
|
+
[](https://codeclimate.com/github/sensortower/sidekiq-throttled)
|
|
6
|
+
[](https://coveralls.io/github/sensortower/sidekiq-throttled?branch=master)
|
|
7
7
|
|
|
8
|
-
Concurrency and threshold throttling for [Sidekiq]
|
|
8
|
+
Concurrency and threshold throttling for [Sidekiq][sidekiq].
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
@@ -126,7 +126,13 @@ versions:
|
|
|
126
126
|
* Ruby 2.2.x
|
|
127
127
|
* Ruby 2.3.x
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
|
|
130
|
+
## Supported Sidekiq Versions
|
|
131
|
+
|
|
132
|
+
This library aims to support work with following [Sidekiq][sidekiq] versions:
|
|
133
|
+
|
|
134
|
+
* Sidekiq 4.0.x
|
|
135
|
+
* Sidekiq 4.1.x
|
|
130
136
|
|
|
131
137
|
|
|
132
138
|
## Contributing
|
|
@@ -143,3 +149,7 @@ versions:
|
|
|
143
149
|
|
|
144
150
|
Copyright (c) 2015 SensorTower Inc.
|
|
145
151
|
See LICENSE.md for further details.
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
[travis]: http://travis-ci.org/sensortower/sidekiq-throttled
|
|
155
|
+
[sidekiq]: https://github.com/mperham/sidekiq
|
data/lib/sidekiq/throttled.rb
CHANGED
|
@@ -42,8 +42,8 @@ module Sidekiq
|
|
|
42
42
|
# @return [void]
|
|
43
43
|
def setup!
|
|
44
44
|
Sidekiq.configure_server do |config|
|
|
45
|
-
require "sidekiq/throttled/
|
|
46
|
-
Sidekiq.options[:fetch] = Sidekiq::Throttled::
|
|
45
|
+
require "sidekiq/throttled/fetch"
|
|
46
|
+
Sidekiq.options[:fetch] = Sidekiq::Throttled::Fetch
|
|
47
47
|
|
|
48
48
|
require "sidekiq/throttled/middleware"
|
|
49
49
|
config.server_middleware do |chain|
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "celluloid" if Sidekiq::VERSION < "4.0.0"
|
|
4
3
|
require "sidekiq"
|
|
5
|
-
require "sidekiq/
|
|
4
|
+
require "sidekiq/throttled/unit_of_work"
|
|
6
5
|
|
|
7
6
|
module Sidekiq
|
|
8
7
|
module Throttled
|
|
9
|
-
# Throttled
|
|
10
|
-
class
|
|
8
|
+
# Throttled fetch strategy.
|
|
9
|
+
class Fetch
|
|
11
10
|
TIMEOUT = 2
|
|
12
|
-
|
|
13
|
-
class UnitOfWork < ::Sidekiq::BasicFetch::UnitOfWork
|
|
14
|
-
alias job message if Sidekiq::VERSION < "4.0.0"
|
|
15
|
-
end
|
|
11
|
+
private_constant :TIMEOUT
|
|
16
12
|
|
|
17
13
|
def initialize(options)
|
|
18
|
-
@strictly_ordered_queues =
|
|
14
|
+
@strictly_ordered_queues = options[:strict]
|
|
19
15
|
@queues = options[:queues].map { |q| "queue:#{q}" }
|
|
20
16
|
@queues.uniq! if @strictly_ordered_queues
|
|
21
17
|
end
|
|
22
18
|
|
|
23
|
-
# @return [Sidekiq::
|
|
19
|
+
# @return [Sidekiq::Throttled::UnitOfWork, nil]
|
|
24
20
|
def retrieve_work
|
|
25
21
|
work = brpop
|
|
26
22
|
return unless work
|
|
@@ -28,9 +24,9 @@ module Sidekiq
|
|
|
28
24
|
work = UnitOfWork.new(*work)
|
|
29
25
|
return work unless Throttled.throttled? work.job
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
Sidekiq.redis do |conn|
|
|
28
|
+
conn.lpush("queue:#{work.queue_name}", work.job)
|
|
29
|
+
end
|
|
34
30
|
|
|
35
31
|
nil
|
|
36
32
|
end
|
|
@@ -40,9 +36,12 @@ module Sidekiq
|
|
|
40
36
|
# Tries to pop pair of `queue` and job `message` out of sidekiq queue.
|
|
41
37
|
# @return [Array<String, String>, nil]
|
|
42
38
|
def brpop
|
|
43
|
-
queues = (@strictly_ordered_queues ? @queues : @queues.shuffle.uniq)
|
|
44
39
|
Sidekiq.redis { |conn| conn.brpop(*queues, TIMEOUT) }
|
|
45
40
|
end
|
|
41
|
+
|
|
42
|
+
def queues
|
|
43
|
+
(@strictly_ordered_queues ? @queues : @queues.shuffle.uniq)
|
|
44
|
+
end
|
|
46
45
|
end
|
|
47
46
|
end
|
|
48
47
|
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "sidekiq"
|
|
4
|
+
|
|
5
|
+
module Sidekiq
|
|
6
|
+
module Throttled
|
|
7
|
+
class UnitOfWork
|
|
8
|
+
QUEUE_NAME_PREFIX_RE = /^.*queue:/
|
|
9
|
+
private_constant :QUEUE_NAME_PREFIX_RE
|
|
10
|
+
|
|
11
|
+
attr_reader :queue
|
|
12
|
+
|
|
13
|
+
attr_reader :job
|
|
14
|
+
|
|
15
|
+
def initialize(queue, job)
|
|
16
|
+
@queue = queue
|
|
17
|
+
@job = job
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def acknowledge
|
|
21
|
+
# do nothing
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def queue_name
|
|
25
|
+
queue.sub(QUEUE_NAME_PREFIX_RE, "")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def requeue
|
|
29
|
+
Sidekiq.redis { |conn| conn.rpush("queue:#{queue_name}", job) }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
</td>
|
|
28
28
|
<td style="vertical-align:middle;text-align:center;">
|
|
29
29
|
<form action="<%= root_path %>throttled/<%= name %>" method="POST">
|
|
30
|
-
<%= csrf_tag
|
|
30
|
+
<%= csrf_tag %>
|
|
31
31
|
<input type="hidden" name="_method" value="delete" />
|
|
32
32
|
<button class="btn btn-danger" type="submit">Reset</button>
|
|
33
33
|
</form>
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sidekiq-throttled
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexey V Zapparov
|
|
@@ -56,13 +56,12 @@ files:
|
|
|
56
56
|
- LICENSE.md
|
|
57
57
|
- README.md
|
|
58
58
|
- Rakefile
|
|
59
|
-
- gemfiles/sidekiq_3.x.gemfile
|
|
60
59
|
- gemfiles/sidekiq_4.0.gemfile
|
|
61
60
|
- gemfiles/sidekiq_4.1.gemfile
|
|
62
61
|
- gemfiles/sidekiq_latest.gemfile
|
|
63
62
|
- lib/sidekiq/throttled.rb
|
|
64
|
-
- lib/sidekiq/throttled/basic_fetch.rb
|
|
65
63
|
- lib/sidekiq/throttled/errors.rb
|
|
64
|
+
- lib/sidekiq/throttled/fetch.rb
|
|
66
65
|
- lib/sidekiq/throttled/middleware.rb
|
|
67
66
|
- lib/sidekiq/throttled/registry.rb
|
|
68
67
|
- lib/sidekiq/throttled/strategy.rb
|
|
@@ -72,6 +71,7 @@ files:
|
|
|
72
71
|
- lib/sidekiq/throttled/strategy/threshold.lua
|
|
73
72
|
- lib/sidekiq/throttled/strategy/threshold.rb
|
|
74
73
|
- lib/sidekiq/throttled/testing.rb
|
|
74
|
+
- lib/sidekiq/throttled/unit_of_work.rb
|
|
75
75
|
- lib/sidekiq/throttled/version.rb
|
|
76
76
|
- lib/sidekiq/throttled/web.rb
|
|
77
77
|
- lib/sidekiq/throttled/web/index.html.erb
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "https://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "appraisal"
|
|
6
|
-
gem "rake"
|
|
7
|
-
gem "rspec"
|
|
8
|
-
gem "rubocop"
|
|
9
|
-
gem "celluloid"
|
|
10
|
-
gem "sidekiq", "~> 3.0"
|
|
11
|
-
|
|
12
|
-
group :test do
|
|
13
|
-
gem "coveralls"
|
|
14
|
-
gem "rack-test"
|
|
15
|
-
gem "simplecov", ">= 0.9"
|
|
16
|
-
gem "sinatra", "~> 1.4", ">= 1.4.6"
|
|
17
|
-
gem "timecop"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
gemspec :path => "../"
|