resque-concurrent-restriction 0.5.7 → 0.5.8
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.
data/CHANGELOG
ADDED
data/README.md
CHANGED
@@ -5,6 +5,8 @@ Resque Concurrent Restriction is a plugin for the [Resque][0] queueing system (h
|
|
5
5
|
|
6
6
|
Resque Concurrent Restriction requires Resque 1.10 and redis 2.2
|
7
7
|
|
8
|
+
[](http://travis-ci.org/wr0ngway/resque-concurrent-restriction)
|
9
|
+
|
8
10
|
Install
|
9
11
|
-------
|
10
12
|
|
@@ -15,18 +17,31 @@ To use
|
|
15
17
|
|
16
18
|
It is especially useful when a system has intensive jobs for which you should only run a few at a time. What you should do for the IntensiveJob is to make it extend Resque::Plugins::ConcurrentRestriction and specify the concurrent limit (defaults to 1). For example:
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
class IntensiveJob
|
21
|
+
extend Resque::Plugins::ConcurrentRestriction
|
22
|
+
concurrent 4
|
23
|
+
|
24
|
+
#rest of your class here
|
25
|
+
end
|
24
26
|
|
25
27
|
That means the IntensiveJob can not have more than 4 jobs running simultaneously
|
26
28
|
|
29
|
+
One can also make the concurrency limit depend on the parameters of a job, for example, if you always pass a user_id as the first param, you can restrict the job to run N concurrent jobs per user:
|
30
|
+
|
31
|
+
class IntensiveJob
|
32
|
+
extend Resque::Plugins::ConcurrentRestriction
|
33
|
+
concurrent 4
|
34
|
+
|
35
|
+
def self.concurrent_identifier(*args)
|
36
|
+
args.first.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
#rest of your class here
|
40
|
+
end
|
41
|
+
|
27
42
|
Author
|
28
43
|
------
|
29
|
-
Code was originally
|
44
|
+
Code was originally forked from the [resque-restriction][1] plugin (Richard Huang :: flyerhzm@gmail.com :: @flyerhzm), but diverged enough that it warranted being its own plugin to keep the code simple.
|
30
45
|
|
31
46
|
Matt Conway :: matt@conwaysplace.com :: @mattconway
|
32
47
|
|
@@ -442,10 +442,18 @@ module Resque
|
|
442
442
|
|
443
443
|
counts_reset = 0
|
444
444
|
count_keys = Resque.redis.keys("concurrent.count.*")
|
445
|
-
|
445
|
+
if count_keys.size > 0
|
446
|
+
count_keys.each_slice(100000) do |key_slice|
|
447
|
+
counts_reset += Resque.redis.del(*key_slice)
|
448
|
+
end
|
449
|
+
end
|
446
450
|
|
447
451
|
runnable_keys = Resque.redis.keys("concurrent.runnable*")
|
448
|
-
|
452
|
+
if runnable_keys.size > 0
|
453
|
+
runnable_keys.each_slice(100000) do |runnable_slice|
|
454
|
+
Resque.redis.del(*runnable_slice)
|
455
|
+
end
|
456
|
+
end
|
449
457
|
|
450
458
|
Resque.redis.del(queue_count_key)
|
451
459
|
queues_enabled = 0
|
@@ -586,6 +586,28 @@ describe Resque::Plugins::ConcurrentRestriction do
|
|
586
586
|
|
587
587
|
end
|
588
588
|
|
589
|
+
it "should handle a large amount of concurrent keys" do
|
590
|
+
# the ruby splat operator will choke on an arguments list greater than a couple hundred thousand objects. make sure this case is handled correctly
|
591
|
+
# It might be better to actually populate redis with a bunch keys but that makes the test pretty slow
|
592
|
+
|
593
|
+
# we have to keep this splat limitation in mind when populating test data, too
|
594
|
+
concurrent_count_keys = 200001.times.collect{ |i| ["concurrent.count.#{i}", "#{i}"] }.flatten
|
595
|
+
concurrent_count_keys.each_slice(100000) do |slice|
|
596
|
+
Resque.redis.mset *slice
|
597
|
+
end
|
598
|
+
|
599
|
+
concurrent_runnable_keys = 200001.times.collect{ |i| ["concurrent.runnable.#{i}", "#{i}"] }.flatten
|
600
|
+
concurrent_runnable_keys.each_slice(100000) do |slice|
|
601
|
+
Resque.redis.mset *slice
|
602
|
+
end
|
603
|
+
|
604
|
+
return_value = nil
|
605
|
+
|
606
|
+
lambda{ return_value = ConcurrentRestrictionJob.reset_restrictions }.should_not raise_exception
|
607
|
+
|
608
|
+
return_value.should == [200001, 0]
|
609
|
+
end
|
610
|
+
|
589
611
|
end
|
590
612
|
|
591
613
|
context "#stats" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-concurrent-restriction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque
|
@@ -100,6 +100,7 @@ extra_rdoc_files: []
|
|
100
100
|
files:
|
101
101
|
- .gitignore
|
102
102
|
- .travis.yml
|
103
|
+
- CHANGELOG
|
103
104
|
- Gemfile
|
104
105
|
- LICENSE
|
105
106
|
- README.md
|