resque-concurrent-restriction 0.5.9 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +2 -0
- data/README.md +1 -1
- data/lib/resque/plugins/concurrent_restriction/concurrent_restriction_job.rb +5 -1
- data/lib/resque/plugins/concurrent_restriction/version.rb +1 -1
- data/resque-concurrent-restriction.gemspec +1 -3
- data/spec/concurrent_restriction_job_spec.rb +698 -700
- data/spec/spec_helper.rb +182 -181
- metadata +19 -46
data/spec/spec_helper.rb
CHANGED
@@ -1,181 +1,182 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'ap'
|
3
|
-
|
4
|
-
require 'resque-concurrent-restriction'
|
5
|
-
|
6
|
-
# No need to start redis when running in Travis
|
7
|
-
unless ENV['CI']
|
8
|
-
|
9
|
-
begin
|
10
|
-
Resque.queues
|
11
|
-
rescue Errno::ECONNREFUSED
|
12
|
-
spec_dir = File.dirname(File.expand_path(__FILE__))
|
13
|
-
REDIS_CMD = "redis-server #{spec_dir}/redis-test.conf"
|
14
|
-
|
15
|
-
puts "Starting redis for testing at localhost..."
|
16
|
-
puts `cd #{spec_dir}; #{REDIS_CMD}`
|
17
|
-
|
18
|
-
# Schedule the redis server for shutdown when tests are all finished.
|
19
|
-
at_exit do
|
20
|
-
puts 'Stopping redis'
|
21
|
-
pid = File.read("#{spec_dir}/redis.pid").to_i rescue nil
|
22
|
-
system ("kill -9 #{pid}") if pid.to_i != 0
|
23
|
-
File.delete("#{spec_dir}/redis.pid") rescue nil
|
24
|
-
File.delete("#{spec_dir}/redis-server.log") rescue nil
|
25
|
-
File.delete("#{spec_dir}/dump.rdb") rescue nil
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
##
|
32
|
-
# Helper to perform job classes
|
33
|
-
#
|
34
|
-
module PerformJob
|
35
|
-
|
36
|
-
def run_resque_job(job_class, *job_args)
|
37
|
-
opts = job_args.last.is_a?(Hash) ? job_args.pop : {}
|
38
|
-
queue = opts[:queue] || Resque.queue_from_class(job_class)
|
39
|
-
|
40
|
-
Resque::Job.create(queue, job_class, *job_args)
|
41
|
-
|
42
|
-
run_resque_queue(queue, opts)
|
43
|
-
end
|
44
|
-
|
45
|
-
def run_resque_queue(queue, opts={})
|
46
|
-
worker = Resque::Worker.new(queue)
|
47
|
-
worker.very_verbose = true if opts[:verbose]
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
worker.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
when '
|
70
|
-
when '
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
Resque.redis.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
keys
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
extend
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
extend
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
extend
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
extend
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
extend
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
extend
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
end
|
1
|
+
require 'rspec'
|
2
|
+
require 'ap'
|
3
|
+
|
4
|
+
require 'resque-concurrent-restriction'
|
5
|
+
|
6
|
+
# No need to start redis when running in Travis
|
7
|
+
unless ENV['CI']
|
8
|
+
|
9
|
+
begin
|
10
|
+
Resque.queues
|
11
|
+
rescue Errno::ECONNREFUSED
|
12
|
+
spec_dir = File.dirname(File.expand_path(__FILE__))
|
13
|
+
REDIS_CMD = "redis-server #{spec_dir}/redis-test.conf"
|
14
|
+
|
15
|
+
puts "Starting redis for testing at localhost..."
|
16
|
+
puts `cd #{spec_dir}; #{REDIS_CMD}`
|
17
|
+
|
18
|
+
# Schedule the redis server for shutdown when tests are all finished.
|
19
|
+
at_exit do
|
20
|
+
puts 'Stopping redis'
|
21
|
+
pid = File.read("#{spec_dir}/redis.pid").to_i rescue nil
|
22
|
+
system ("kill -9 #{pid}") if pid.to_i != 0
|
23
|
+
File.delete("#{spec_dir}/redis.pid") rescue nil
|
24
|
+
File.delete("#{spec_dir}/redis-server.log") rescue nil
|
25
|
+
File.delete("#{spec_dir}/dump.rdb") rescue nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Helper to perform job classes
|
33
|
+
#
|
34
|
+
module PerformJob
|
35
|
+
|
36
|
+
def run_resque_job(job_class, *job_args)
|
37
|
+
opts = job_args.last.is_a?(Hash) ? job_args.pop : {}
|
38
|
+
queue = opts[:queue] || Resque.queue_from_class(job_class)
|
39
|
+
|
40
|
+
Resque::Job.create(queue, job_class, *job_args)
|
41
|
+
|
42
|
+
run_resque_queue(queue, opts)
|
43
|
+
end
|
44
|
+
|
45
|
+
def run_resque_queue(queue, opts={})
|
46
|
+
worker = Resque::Worker.new(queue)
|
47
|
+
worker.very_verbose = true if opts[:verbose]
|
48
|
+
worker.term_child = true
|
49
|
+
|
50
|
+
# do a single job then shutdown
|
51
|
+
def worker.done_working
|
52
|
+
super
|
53
|
+
shutdown
|
54
|
+
end
|
55
|
+
|
56
|
+
if opts[:inline]
|
57
|
+
job = worker.reserve
|
58
|
+
worker.perform(job)
|
59
|
+
else
|
60
|
+
worker.work(0)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def dump_redis
|
65
|
+
result = {}
|
66
|
+
Resque.redis.keys("*").each do |key|
|
67
|
+
type = Resque.redis.type(key)
|
68
|
+
result[key] = case type
|
69
|
+
when 'string' then Resque.redis.get(key)
|
70
|
+
when 'list' then Resque.redis.lrange(key, 0, -1)
|
71
|
+
when 'set' then Resque.redis.smembers(key)
|
72
|
+
else type
|
73
|
+
end
|
74
|
+
end
|
75
|
+
return result
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
module RunCountHelper
|
81
|
+
|
82
|
+
def around_perform(*args)
|
83
|
+
begin
|
84
|
+
Resque.redis.set("restricted_job_started:#{self}:#{args.to_json}", true)
|
85
|
+
Resque.redis.incr("restricted_job_run_count:#{self}:#{args.to_json}")
|
86
|
+
yield
|
87
|
+
ensure
|
88
|
+
Resque.redis.set("restricted_job_ended:#{self}:#{args.to_json}", true)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def perform(*args)
|
93
|
+
#puts "Running job #{self}:#{args}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def run_count(*args)
|
97
|
+
Resque.redis.get("restricted_job_run_count:#{self}:#{args.to_json}").to_i
|
98
|
+
end
|
99
|
+
|
100
|
+
def total_run_count
|
101
|
+
keys = Resque.redis.keys("restricted_job_run_count:#{self}:*")
|
102
|
+
keys.inject(0) {|sum, k| sum + Resque.redis.get(k).to_i }
|
103
|
+
end
|
104
|
+
|
105
|
+
def started?(*args)
|
106
|
+
return Resque.redis.get("restricted_job_started#{self}:#{args.to_json}") == true
|
107
|
+
end
|
108
|
+
|
109
|
+
def ended?(*args)
|
110
|
+
return Resque.redis.get("restricted_job_ended#{self}:#{args.to_json}") == true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
class NoRestrictionJob
|
115
|
+
extend RunCountHelper
|
116
|
+
@queue = 'normal'
|
117
|
+
end
|
118
|
+
|
119
|
+
class RestrictionJob
|
120
|
+
extend RunCountHelper
|
121
|
+
extend Resque::Plugins::ConcurrentRestriction
|
122
|
+
concurrent 1
|
123
|
+
@queue = 'normal'
|
124
|
+
end
|
125
|
+
|
126
|
+
module Jobs
|
127
|
+
class NestedRestrictionJob
|
128
|
+
extend RunCountHelper
|
129
|
+
extend Resque::Plugins::ConcurrentRestriction
|
130
|
+
concurrent 1
|
131
|
+
@queue = 'normal'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class IdentifiedRestrictionJob
|
136
|
+
extend RunCountHelper
|
137
|
+
extend Resque::Plugins::ConcurrentRestriction
|
138
|
+
concurrent 1
|
139
|
+
@queue = 'normal'
|
140
|
+
|
141
|
+
def self.concurrent_identifier(*args)
|
142
|
+
args.first.to_s
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
class ConcurrentRestrictionJob
|
148
|
+
extend RunCountHelper
|
149
|
+
extend Resque::Plugins::ConcurrentRestriction
|
150
|
+
concurrent 1
|
151
|
+
|
152
|
+
@queue = 'normal'
|
153
|
+
|
154
|
+
def self.perform(*args)
|
155
|
+
raise args.first if args.first
|
156
|
+
sleep 0.2
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class MultipleConcurrentRestrictionJob
|
161
|
+
extend RunCountHelper
|
162
|
+
extend Resque::Plugins::ConcurrentRestriction
|
163
|
+
concurrent 4
|
164
|
+
|
165
|
+
@queue = 'normal'
|
166
|
+
|
167
|
+
def self.perform(*args)
|
168
|
+
sleep 0.5
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
class OneConcurrentRestrictionJob
|
173
|
+
extend RunCountHelper
|
174
|
+
extend Resque::Plugins::ConcurrentRestriction
|
175
|
+
concurrent 1
|
176
|
+
|
177
|
+
@queue = 'normal'
|
178
|
+
|
179
|
+
def self.perform(*args)
|
180
|
+
sleep 0.5
|
181
|
+
end
|
182
|
+
end
|
metadata
CHANGED
@@ -1,94 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-concurrent-restriction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Matt Conway
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: resque
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '1.
|
19
|
+
version: '1.25'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: json
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
26
|
+
version: '1.25'
|
46
27
|
- !ruby/object:Gem::Dependency
|
47
28
|
name: rspec
|
48
29
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
30
|
requirements:
|
51
|
-
- - ~>
|
31
|
+
- - "~>"
|
52
32
|
- !ruby/object:Gem::Version
|
53
33
|
version: '2.5'
|
54
34
|
type: :development
|
55
35
|
prerelease: false
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
37
|
requirements:
|
59
|
-
- - ~>
|
38
|
+
- - "~>"
|
60
39
|
- !ruby/object:Gem::Version
|
61
40
|
version: '2.5'
|
62
41
|
- !ruby/object:Gem::Dependency
|
63
42
|
name: awesome_print
|
64
43
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
44
|
requirements:
|
67
|
-
- -
|
45
|
+
- - ">="
|
68
46
|
- !ruby/object:Gem::Version
|
69
47
|
version: '0'
|
70
48
|
type: :development
|
71
49
|
prerelease: false
|
72
50
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
51
|
requirements:
|
75
|
-
- -
|
52
|
+
- - ">="
|
76
53
|
- !ruby/object:Gem::Version
|
77
54
|
version: '0'
|
78
55
|
- !ruby/object:Gem::Dependency
|
79
56
|
name: json
|
80
57
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
58
|
requirements:
|
83
|
-
- -
|
59
|
+
- - ">="
|
84
60
|
- !ruby/object:Gem::Version
|
85
61
|
version: '0'
|
86
62
|
type: :development
|
87
63
|
prerelease: false
|
88
64
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
65
|
requirements:
|
91
|
-
- -
|
66
|
+
- - ">="
|
92
67
|
- !ruby/object:Gem::Version
|
93
68
|
version: '0'
|
94
69
|
description: A resque plugin for limiting how many of a specific job can run concurrently
|
@@ -98,8 +73,8 @@ executables: []
|
|
98
73
|
extensions: []
|
99
74
|
extra_rdoc_files: []
|
100
75
|
files:
|
101
|
-
- .gitignore
|
102
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
103
78
|
- CHANGELOG
|
104
79
|
- Gemfile
|
105
80
|
- LICENSE
|
@@ -117,27 +92,26 @@ files:
|
|
117
92
|
- spec/spec_helper.rb
|
118
93
|
homepage: http://github.com/wr0ngway/resque-concurrent-restriction
|
119
94
|
licenses: []
|
95
|
+
metadata: {}
|
120
96
|
post_install_message:
|
121
97
|
rdoc_options: []
|
122
98
|
require_paths:
|
123
99
|
- lib
|
124
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
-
none: false
|
126
101
|
requirements:
|
127
|
-
- -
|
102
|
+
- - ">="
|
128
103
|
- !ruby/object:Gem::Version
|
129
104
|
version: '0'
|
130
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
-
none: false
|
132
106
|
requirements:
|
133
|
-
- -
|
107
|
+
- - ">="
|
134
108
|
- !ruby/object:Gem::Version
|
135
109
|
version: '0'
|
136
110
|
requirements: []
|
137
111
|
rubyforge_project: resque-concurrent-restriction
|
138
|
-
rubygems_version:
|
112
|
+
rubygems_version: 2.4.5.1
|
139
113
|
signing_key:
|
140
|
-
specification_version:
|
114
|
+
specification_version: 4
|
141
115
|
summary: A resque plugin for limiting how many of a specific job can run concurrently
|
142
116
|
test_files:
|
143
117
|
- spec/concurrent_restriction_job_spec.rb
|
@@ -145,4 +119,3 @@ test_files:
|
|
145
119
|
- spec/resque_worker_extensions_spec.rb
|
146
120
|
- spec/spec.opts
|
147
121
|
- spec/spec_helper.rb
|
148
|
-
has_rdoc:
|