sidekiq-limit_fetch 2.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +8 -1
- data/benchmarks/compare.rb +1 -1
- data/lib/sidekiq/limit_fetch/global/selector.rb +2 -9
- data/lib/sidekiq/limit_fetch/global/semaphore.rb +2 -3
- data/lib/sidekiq/limit_fetch/queues.rb +5 -3
- data/lib/sidekiq/limit_fetch/redis.rb +16 -2
- data/lib/sidekiq/limit_fetch.rb +2 -2
- data/sidekiq-limit_fetch.gemspec +1 -1
- data/spec/sidekiq/limit_fetch/queues_spec.rb +2 -1
- data/spec/spec_helper.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4db872c28ebde76d915d79b0a0bdbdbcf9859b38
|
4
|
+
data.tar.gz: 9c6104f1869c2979a9e908f01ca6035d3319e134
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28706d72d599cc68bb431edafdbfb886a4438b92e165257ae5fe862aee16899d530a5c96fa42c75a2f7f8155105e6d0219bdbfb91493d1bfd7c49eff26dcf605
|
7
|
+
data.tar.gz: 4dc6225e29e2aa26a64867f9dda5eee538000e443e713da38bd3b4d124aa5bfafbf563ec72214e6df120e90af30af5a7d5cdac014426196b398adfb90e637e2f
|
data/Rakefile
CHANGED
data/benchmarks/compare.rb
CHANGED
@@ -8,7 +8,7 @@ limit = ARGV.shift
|
|
8
8
|
if limit
|
9
9
|
limit = nil if limit == 'nil'
|
10
10
|
|
11
|
-
$:.unshift File.expand_path '
|
11
|
+
$:.unshift File.expand_path '../lib'
|
12
12
|
require 'sidekiq-limit_fetch'
|
13
13
|
Sidekiq::Queue['inline'].limit = limit
|
14
14
|
Sidekiq.redis {|it| it.del 'limit_fetch:probed:inline' }
|
@@ -2,11 +2,11 @@ module Sidekiq::LimitFetch::Global
|
|
2
2
|
module Selector
|
3
3
|
extend self
|
4
4
|
|
5
|
-
def acquire(queues)
|
5
|
+
def acquire(queues, namespace)
|
6
6
|
redis_eval :acquire, [namespace, uuid, queues]
|
7
7
|
end
|
8
8
|
|
9
|
-
def release(queues)
|
9
|
+
def release(queues, namespace)
|
10
10
|
redis_eval :release, [namespace, uuid, queues]
|
11
11
|
end
|
12
12
|
|
@@ -22,13 +22,6 @@ module Sidekiq::LimitFetch::Global
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
def namespace
|
26
|
-
@namespace ||= begin
|
27
|
-
namespace = Sidekiq.options[:namespace]
|
28
|
-
namespace + ':' if namespace
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
25
|
def redis_eval(script_name, args)
|
33
26
|
Sidekiq.redis do |it|
|
34
27
|
begin
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Sidekiq::LimitFetch::Global
|
2
2
|
class Semaphore
|
3
|
-
|
4
|
-
def_delegator Sidekiq, :redis
|
3
|
+
include Sidekiq::LimitFetch::Redis
|
5
4
|
|
6
5
|
PREFIX = 'limit_fetch'
|
7
6
|
|
@@ -19,7 +18,7 @@ module Sidekiq::LimitFetch::Global
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def acquire
|
22
|
-
Selector.acquire([@name]).size > 0
|
21
|
+
Selector.acquire([@name], determine_namespace).size > 0
|
23
22
|
end
|
24
23
|
|
25
24
|
def release
|
@@ -3,7 +3,9 @@ class Sidekiq::LimitFetch
|
|
3
3
|
THREAD_KEY = :acquired_queues
|
4
4
|
|
5
5
|
def initialize(options)
|
6
|
-
@queues
|
6
|
+
@queues = options[:queues]
|
7
|
+
@namespace = options[:namespace]
|
8
|
+
|
7
9
|
options[:strict] ? strict_order! : weighted_order!
|
8
10
|
|
9
11
|
set_limits options[:limits]
|
@@ -11,7 +13,7 @@ class Sidekiq::LimitFetch
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def acquire
|
14
|
-
selector.acquire(ordered_queues)
|
16
|
+
selector.acquire(ordered_queues, @namespace)
|
15
17
|
.tap {|it| save it }
|
16
18
|
.map {|it| "queue:#{it}" }
|
17
19
|
end
|
@@ -19,7 +21,7 @@ class Sidekiq::LimitFetch
|
|
19
21
|
def release_except(full_name)
|
20
22
|
queues = restore
|
21
23
|
queues.delete full_name[/queue:(.*)/, 1] if full_name
|
22
|
-
selector.release queues
|
24
|
+
selector.release queues, @namespace
|
23
25
|
end
|
24
26
|
|
25
27
|
private
|
@@ -1,13 +1,27 @@
|
|
1
1
|
module Sidekiq::LimitFetch::Redis
|
2
|
+
extend self
|
3
|
+
|
2
4
|
# prevent blocking of fetcher
|
3
5
|
# more bullet-proof and faster (O_O)
|
4
6
|
# than using Celluloid::IO
|
5
|
-
def
|
6
|
-
|
7
|
+
def nonblocking_redis
|
8
|
+
redis do |redis|
|
7
9
|
begin
|
8
10
|
Celluloid::Future.new { yield redis }.value
|
9
11
|
end
|
10
12
|
end
|
11
13
|
rescue Celluloid::Task::TerminatedError
|
12
14
|
end
|
15
|
+
|
16
|
+
def redis
|
17
|
+
Sidekiq.redis {|it| yield it }
|
18
|
+
end
|
19
|
+
|
20
|
+
def determine_namespace
|
21
|
+
redis do |it|
|
22
|
+
if it.respond_to?(:namespace) and it.namespace
|
23
|
+
it.namespace + ':'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
13
27
|
end
|
data/lib/sidekiq/limit_fetch.rb
CHANGED
@@ -21,7 +21,7 @@ class Sidekiq::LimitFetch
|
|
21
21
|
|
22
22
|
def initialize(options)
|
23
23
|
Global::Monitor.start!
|
24
|
-
@queues = Queues.new options
|
24
|
+
@queues = Queues.new options.merge(namespace: determine_namespace)
|
25
25
|
end
|
26
26
|
|
27
27
|
def retrieve_work
|
@@ -39,6 +39,6 @@ class Sidekiq::LimitFetch
|
|
39
39
|
|
40
40
|
def redis_brpop(*args)
|
41
41
|
return if args.size < 2
|
42
|
-
|
42
|
+
nonblocking_redis {|it| it.brpop *args }
|
43
43
|
end
|
44
44
|
end
|
data/sidekiq-limit_fetch.gemspec
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-limit_fetch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brainopia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|