resque-igo 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +225 -0
- data/LICENSE +20 -0
- data/README.markdown +855 -0
- data/Rakefile +70 -0
- data/bin/resque +57 -0
- data/bin/resque-web +23 -0
- data/lib/resque.rb +380 -0
- data/lib/resque/errors.rb +10 -0
- data/lib/resque/failure.rb +66 -0
- data/lib/resque/failure/base.rb +61 -0
- data/lib/resque/failure/hoptoad.rb +132 -0
- data/lib/resque/failure/multiple.rb +50 -0
- data/lib/resque/failure/redis.rb +40 -0
- data/lib/resque/helpers.rb +71 -0
- data/lib/resque/job.rb +209 -0
- data/lib/resque/plugin.rb +51 -0
- data/lib/resque/server.rb +247 -0
- data/lib/resque/server/public/idle.png +0 -0
- data/lib/resque/server/public/jquery-1.3.2.min.js +19 -0
- data/lib/resque/server/public/jquery.relatize_date.js +95 -0
- data/lib/resque/server/public/poll.png +0 -0
- data/lib/resque/server/public/ranger.js +67 -0
- data/lib/resque/server/public/reset.css +48 -0
- data/lib/resque/server/public/style.css +86 -0
- data/lib/resque/server/public/working.png +0 -0
- data/lib/resque/server/test_helper.rb +19 -0
- data/lib/resque/server/views/error.erb +1 -0
- data/lib/resque/server/views/failed.erb +53 -0
- data/lib/resque/server/views/key_sets.erb +20 -0
- data/lib/resque/server/views/key_string.erb +11 -0
- data/lib/resque/server/views/layout.erb +42 -0
- data/lib/resque/server/views/next_more.erb +10 -0
- data/lib/resque/server/views/overview.erb +4 -0
- data/lib/resque/server/views/queues.erb +65 -0
- data/lib/resque/server/views/stats.erb +73 -0
- data/lib/resque/server/views/workers.erb +109 -0
- data/lib/resque/server/views/working.erb +68 -0
- data/lib/resque/stat.rb +54 -0
- data/lib/resque/tasks.rb +39 -0
- data/lib/resque/version.rb +3 -0
- data/lib/resque/worker.rb +478 -0
- data/tasks/resque.rake +2 -0
- data/test/job_hooks_test.rb +323 -0
- data/test/job_plugins_test.rb +230 -0
- data/test/plugin_test.rb +116 -0
- data/test/resque-web_test.rb +54 -0
- data/test/resque_test.rb +351 -0
- data/test/test_helper.rb +166 -0
- data/test/worker_test.rb +302 -0
- metadata +180 -0
data/test/plugin_test.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
context "Resque::Plugin finding hooks" do
|
4
|
+
module SimplePlugin
|
5
|
+
extend self
|
6
|
+
def before_perform1; end
|
7
|
+
def before_perform; end
|
8
|
+
def before_perform2; end
|
9
|
+
def after_perform1; end
|
10
|
+
def after_perform; end
|
11
|
+
def after_perform2; end
|
12
|
+
def perform; end
|
13
|
+
def around_perform1; end
|
14
|
+
def around_perform; end
|
15
|
+
def around_perform2; end
|
16
|
+
def on_failure1; end
|
17
|
+
def on_failure; end
|
18
|
+
def on_failure2; end
|
19
|
+
end
|
20
|
+
|
21
|
+
test "before_perform hooks are found and sorted" do
|
22
|
+
assert_equal ["before_perform", "before_perform1", "before_perform2"], Resque::Plugin.before_hooks(SimplePlugin).map {|m| m.to_s}
|
23
|
+
end
|
24
|
+
|
25
|
+
test "after_perform hooks are found and sorted" do
|
26
|
+
assert_equal ["after_perform", "after_perform1", "after_perform2"], Resque::Plugin.after_hooks(SimplePlugin).map {|m| m.to_s}
|
27
|
+
end
|
28
|
+
|
29
|
+
test "around_perform hooks are found and sorted" do
|
30
|
+
assert_equal ["around_perform", "around_perform1", "around_perform2"], Resque::Plugin.around_hooks(SimplePlugin).map {|m| m.to_s}
|
31
|
+
end
|
32
|
+
|
33
|
+
test "on_failure hooks are found and sorted" do
|
34
|
+
assert_equal ["on_failure", "on_failure1", "on_failure2"], Resque::Plugin.failure_hooks(SimplePlugin).map {|m| m.to_s}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "Resque::Plugin linting" do
|
39
|
+
module ::BadBefore
|
40
|
+
def self.before_perform; end
|
41
|
+
end
|
42
|
+
module ::BadAfter
|
43
|
+
def self.after_perform; end
|
44
|
+
end
|
45
|
+
module ::BadAround
|
46
|
+
def self.around_perform; end
|
47
|
+
end
|
48
|
+
module ::BadFailure
|
49
|
+
def self.on_failure; end
|
50
|
+
end
|
51
|
+
|
52
|
+
test "before_perform must be namespaced" do
|
53
|
+
begin
|
54
|
+
Resque::Plugin.lint(BadBefore)
|
55
|
+
assert false, "should have failed"
|
56
|
+
rescue Resque::Plugin::LintError => e
|
57
|
+
assert_equal "BadBefore.before_perform is not namespaced", e.message
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
test "after_perform must be namespaced" do
|
62
|
+
begin
|
63
|
+
Resque::Plugin.lint(BadAfter)
|
64
|
+
assert false, "should have failed"
|
65
|
+
rescue Resque::Plugin::LintError => e
|
66
|
+
assert_equal "BadAfter.after_perform is not namespaced", e.message
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
test "around_perform must be namespaced" do
|
71
|
+
begin
|
72
|
+
Resque::Plugin.lint(BadAround)
|
73
|
+
assert false, "should have failed"
|
74
|
+
rescue Resque::Plugin::LintError => e
|
75
|
+
assert_equal "BadAround.around_perform is not namespaced", e.message
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
test "on_failure must be namespaced" do
|
80
|
+
begin
|
81
|
+
Resque::Plugin.lint(BadFailure)
|
82
|
+
assert false, "should have failed"
|
83
|
+
rescue Resque::Plugin::LintError => e
|
84
|
+
assert_equal "BadFailure.on_failure is not namespaced", e.message
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
module GoodBefore
|
89
|
+
def self.before_perform1; end
|
90
|
+
end
|
91
|
+
module GoodAfter
|
92
|
+
def self.after_perform1; end
|
93
|
+
end
|
94
|
+
module GoodAround
|
95
|
+
def self.around_perform1; end
|
96
|
+
end
|
97
|
+
module GoodFailure
|
98
|
+
def self.on_failure1; end
|
99
|
+
end
|
100
|
+
|
101
|
+
test "before_perform1 is an ok name" do
|
102
|
+
Resque::Plugin.lint(GoodBefore)
|
103
|
+
end
|
104
|
+
|
105
|
+
test "after_perform1 is an ok name" do
|
106
|
+
Resque::Plugin.lint(GoodAfter)
|
107
|
+
end
|
108
|
+
|
109
|
+
test "around_perform1 is an ok name" do
|
110
|
+
Resque::Plugin.lint(GoodAround)
|
111
|
+
end
|
112
|
+
|
113
|
+
test "on_failure1 is an ok name" do
|
114
|
+
Resque::Plugin.lint(GoodFailure)
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'resque/server/test_helper'
|
3
|
+
|
4
|
+
# Root path test
|
5
|
+
context "on GET to /" do
|
6
|
+
setup { get "/" }
|
7
|
+
|
8
|
+
test "redirect to overview" do
|
9
|
+
follow_redirect!
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Global overview
|
14
|
+
context "on GET to /overview" do
|
15
|
+
setup { get "/overview" }
|
16
|
+
|
17
|
+
test "should at least display 'queues'" do
|
18
|
+
assert last_response.body.include?('Queues')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Working jobs
|
23
|
+
context "on GET to /working" do
|
24
|
+
setup { get "/working" }
|
25
|
+
|
26
|
+
should_respond_with_success
|
27
|
+
end
|
28
|
+
|
29
|
+
# Failed
|
30
|
+
context "on GET to /failed" do
|
31
|
+
setup { get "/failed" }
|
32
|
+
|
33
|
+
should_respond_with_success
|
34
|
+
end
|
35
|
+
|
36
|
+
# Stats
|
37
|
+
context "on GET to /stats/resque" do
|
38
|
+
setup { get "/stats/resque" }
|
39
|
+
|
40
|
+
should_respond_with_success
|
41
|
+
end
|
42
|
+
|
43
|
+
context "on GET to /stats/redis" do
|
44
|
+
setup { get "/stats/redis" }
|
45
|
+
|
46
|
+
should_respond_with_success
|
47
|
+
end
|
48
|
+
|
49
|
+
context "on GET to /stats/resque" do
|
50
|
+
setup { get "/stats/keys" }
|
51
|
+
|
52
|
+
should_respond_with_success
|
53
|
+
end
|
54
|
+
|
data/test/resque_test.rb
ADDED
@@ -0,0 +1,351 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
context "Resque" do
|
4
|
+
setup do
|
5
|
+
Resque.drop
|
6
|
+
Resque.bypass_queues = false
|
7
|
+
Resque.enable_delay(:delayed)
|
8
|
+
Resque.push(:people, { 'name' => 'chris' })
|
9
|
+
Resque.push(:people, { 'name' => 'bob' })
|
10
|
+
Resque.push(:people, { 'name' => 'mark' })
|
11
|
+
end
|
12
|
+
|
13
|
+
test "can set a namespace through a url-like string" do
|
14
|
+
assert Resque.mongo
|
15
|
+
assert_equal 'resque', Resque.mongo.name
|
16
|
+
Resque.mongo = 'localhost:27017/namespace'
|
17
|
+
assert_equal 'namespace', Resque.mongo.name
|
18
|
+
end
|
19
|
+
|
20
|
+
test "can put jobs on a queue" do
|
21
|
+
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
|
22
|
+
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
|
23
|
+
end
|
24
|
+
|
25
|
+
test "can grab jobs off a queue" do
|
26
|
+
Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
|
27
|
+
|
28
|
+
job = Resque.reserve(:jobs)
|
29
|
+
|
30
|
+
assert_kind_of Resque::Job, job
|
31
|
+
assert_equal SomeJob, job.payload_class
|
32
|
+
assert_equal 20, job.args[0]
|
33
|
+
assert_equal '/tmp', job.args[1]
|
34
|
+
end
|
35
|
+
|
36
|
+
test "can re-queue jobs" do
|
37
|
+
Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
|
38
|
+
|
39
|
+
job = Resque.reserve(:jobs)
|
40
|
+
job.recreate
|
41
|
+
|
42
|
+
assert_equal job, Resque.reserve(:jobs)
|
43
|
+
end
|
44
|
+
|
45
|
+
test "can put jobs on a queue by way of an ivar" do
|
46
|
+
assert_equal 0, Resque.size(:ivar)
|
47
|
+
assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
|
48
|
+
assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
|
49
|
+
|
50
|
+
job = Resque.reserve(:ivar)
|
51
|
+
|
52
|
+
assert_kind_of Resque::Job, job
|
53
|
+
assert_equal SomeIvarJob, job.payload_class
|
54
|
+
assert_equal 20, job.args[0]
|
55
|
+
assert_equal '/tmp', job.args[1]
|
56
|
+
|
57
|
+
assert Resque.reserve(:ivar)
|
58
|
+
assert_equal nil, Resque.reserve(:ivar)
|
59
|
+
end
|
60
|
+
|
61
|
+
test "can remove jobs from a queue by way of an ivar" do
|
62
|
+
assert_equal 0, Resque.size(:ivar)
|
63
|
+
assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
|
64
|
+
assert Resque.enqueue(SomeIvarJob, 30, '/tmp')
|
65
|
+
assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
|
66
|
+
assert Resque::Job.create(:ivar, 'blah-job', 20, '/tmp')
|
67
|
+
assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
|
68
|
+
assert_equal 5, Resque.size(:ivar)
|
69
|
+
|
70
|
+
assert Resque.dequeue(SomeIvarJob, 30, '/tmp')
|
71
|
+
assert_equal 4, Resque.size(:ivar)
|
72
|
+
assert Resque.dequeue(SomeIvarJob)
|
73
|
+
assert_equal 1, Resque.size(:ivar)
|
74
|
+
end
|
75
|
+
|
76
|
+
test "jobs have a nice #inspect" do
|
77
|
+
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
|
78
|
+
job = Resque.reserve(:jobs)
|
79
|
+
assert_equal '(Job{jobs} | SomeJob | [20, "/tmp"])', job.inspect
|
80
|
+
end
|
81
|
+
|
82
|
+
test "jobs can be destroyed" do
|
83
|
+
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
|
84
|
+
assert Resque::Job.create(:jobs, 'BadJob', 20, '/tmp')
|
85
|
+
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
|
86
|
+
assert Resque::Job.create(:jobs, 'BadJob', 30, '/tmp')
|
87
|
+
assert Resque::Job.create(:jobs, 'BadJob', 20, '/tmp')
|
88
|
+
|
89
|
+
assert_equal 5, Resque.size(:jobs)
|
90
|
+
assert_equal 2, Resque::Job.destroy(:jobs, 'SomeJob')
|
91
|
+
assert_equal 3, Resque.size(:jobs)
|
92
|
+
assert_equal 1, Resque::Job.destroy(:jobs, 'BadJob', 30, '/tmp')
|
93
|
+
assert_equal 2, Resque.size(:jobs)
|
94
|
+
end
|
95
|
+
|
96
|
+
test "jobs can test for equality" do
|
97
|
+
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
|
98
|
+
assert Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
|
99
|
+
assert_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
|
100
|
+
|
101
|
+
assert Resque::Job.create(:jobs, 'SomeMethodJob', 20, '/tmp')
|
102
|
+
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
|
103
|
+
assert_not_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
|
104
|
+
|
105
|
+
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
|
106
|
+
assert Resque::Job.create(:jobs, 'SomeJob', 30, '/tmp')
|
107
|
+
assert_not_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
|
108
|
+
end
|
109
|
+
|
110
|
+
test "can put jobs on a queue by way of a method" do
|
111
|
+
assert_equal 0, Resque.size(:method)
|
112
|
+
assert Resque.enqueue(SomeMethodJob, 20, '/tmp')
|
113
|
+
assert Resque.enqueue(SomeMethodJob, 20, '/tmp')
|
114
|
+
|
115
|
+
job = Resque.reserve(:method)
|
116
|
+
|
117
|
+
assert_kind_of Resque::Job, job
|
118
|
+
assert_equal SomeMethodJob, job.payload_class
|
119
|
+
assert_equal 20, job.args[0]
|
120
|
+
assert_equal '/tmp', job.args[1]
|
121
|
+
|
122
|
+
assert Resque.reserve(:method)
|
123
|
+
assert_equal nil, Resque.reserve(:method)
|
124
|
+
end
|
125
|
+
|
126
|
+
test "needs to infer a queue with enqueue" do
|
127
|
+
assert_raises Resque::NoQueueError do
|
128
|
+
Resque.enqueue(SomeJob, 20, '/tmp')
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
test "can put items on a queue" do
|
133
|
+
assert Resque.push(:people, { 'name' => 'jon' })
|
134
|
+
end
|
135
|
+
|
136
|
+
def pop_no_id(queue)
|
137
|
+
item = Resque.pop(queue)
|
138
|
+
item.delete("_id")
|
139
|
+
item
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
test "can pull items off a queue" do
|
144
|
+
assert_equal({ 'name' => 'chris' }, pop_no_id(:people))
|
145
|
+
assert_equal({ 'name' => 'bob' }, pop_no_id(:people))
|
146
|
+
assert_equal({ 'name' => 'mark' }, pop_no_id(:people))
|
147
|
+
assert_equal nil, Resque.pop(:people)
|
148
|
+
end
|
149
|
+
|
150
|
+
test "knows how big a queue is" do
|
151
|
+
assert_equal 3, Resque.size(:people)
|
152
|
+
|
153
|
+
assert_equal({ 'name' => 'chris' }, pop_no_id(:people))
|
154
|
+
assert_equal 2, Resque.size(:people)
|
155
|
+
|
156
|
+
assert_equal({ 'name' => 'bob' }, pop_no_id(:people))
|
157
|
+
assert_equal({ 'name' => 'mark' }, pop_no_id(:people))
|
158
|
+
assert_equal 0, Resque.size(:people)
|
159
|
+
end
|
160
|
+
|
161
|
+
test "can peek at a queue" do
|
162
|
+
peek = Resque.peek(:people)
|
163
|
+
peek.delete "_id"
|
164
|
+
assert_equal({ 'name' => 'chris' }, peek)
|
165
|
+
assert_equal 3, Resque.size(:people)
|
166
|
+
end
|
167
|
+
|
168
|
+
test "can peek multiple items on a queue" do
|
169
|
+
assert_equal('bob', Resque.peek(:people, 1, 1)['name'])
|
170
|
+
peek = Resque.peek(:people, 1, 2).map { |hash| { 'name' => hash['name']}}
|
171
|
+
assert_equal([{ 'name' => 'bob' }, { 'name' => 'mark' }], peek)
|
172
|
+
peek = Resque.peek(:people, 0, 2).map { |hash| { 'name' => hash['name']} }
|
173
|
+
assert_equal([{ 'name' => 'chris' }, { 'name' => 'bob' }], peek)
|
174
|
+
peek = Resque.peek(:people, 0, 3).map { |hash| { 'name' => hash['name']} }
|
175
|
+
assert_equal([{ 'name' => 'chris' }, { 'name' => 'bob' }, { 'name' => 'mark' }], peek)
|
176
|
+
peek = Resque.peek(:people, 2, 1)
|
177
|
+
assert_equal('mark', peek['name'])
|
178
|
+
assert_equal nil, Resque.peek(:people, 3)
|
179
|
+
assert_equal [], Resque.peek(:people, 3, 2)
|
180
|
+
end
|
181
|
+
|
182
|
+
test "knows what queues it is managing" do
|
183
|
+
assert_equal %w( people ), Resque.queues
|
184
|
+
Resque.push(:cars, { 'make' => 'bmw' })
|
185
|
+
assert_equal %w( cars people ), Resque.queues.sort
|
186
|
+
end
|
187
|
+
|
188
|
+
test "queues are always a list" do
|
189
|
+
Resque.drop
|
190
|
+
assert_equal [], Resque.queues
|
191
|
+
end
|
192
|
+
|
193
|
+
test "can delete a queue" do
|
194
|
+
Resque.push(:cars, { 'make' => 'bmw' })
|
195
|
+
assert_equal %w( cars people ), Resque.queues.sort
|
196
|
+
Resque.remove_queue(:people)
|
197
|
+
assert_equal %w( cars ), Resque.queues
|
198
|
+
assert_equal nil, Resque.pop(:people)
|
199
|
+
end
|
200
|
+
|
201
|
+
test "keeps track of resque keys" do
|
202
|
+
assert Resque.keys.include? 'people'
|
203
|
+
end
|
204
|
+
|
205
|
+
test "badly wants a class name, too" do
|
206
|
+
assert_raises Resque::NoClassError do
|
207
|
+
Resque::Job.create(:jobs, nil)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
test "keeps stats" do
|
212
|
+
Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
|
213
|
+
Resque::Job.create(:jobs, BadJob)
|
214
|
+
Resque::Job.create(:jobs, GoodJob)
|
215
|
+
|
216
|
+
Resque::Job.create(:others, GoodJob)
|
217
|
+
Resque::Job.create(:others, GoodJob)
|
218
|
+
|
219
|
+
stats = Resque.info
|
220
|
+
assert_equal 8, stats[:pending]
|
221
|
+
|
222
|
+
@worker = Resque::Worker.new(:jobs)
|
223
|
+
@worker.register_worker
|
224
|
+
2.times { @worker.process }
|
225
|
+
|
226
|
+
job = @worker.reserve
|
227
|
+
@worker.working_on job
|
228
|
+
|
229
|
+
stats = Resque.info
|
230
|
+
assert_equal 1, stats[:working]
|
231
|
+
assert_equal 1, stats[:workers]
|
232
|
+
|
233
|
+
@worker.done_working
|
234
|
+
|
235
|
+
stats = Resque.info
|
236
|
+
assert_equal 3, stats[:queues]
|
237
|
+
assert_equal 3, stats[:processed]
|
238
|
+
assert_equal 1, stats[:failed]
|
239
|
+
# assert_equal [Resque.redis.respond_to?(:server) ? 'localhost:9736' : 'redis://localhost:9736/0'], stats[:servers]
|
240
|
+
end
|
241
|
+
|
242
|
+
test "decode bad json" do
|
243
|
+
assert_nil Resque.decode("{\"error\":\"Module not found \\u002\"}")
|
244
|
+
end
|
245
|
+
|
246
|
+
test "unique jobs are unique" do
|
247
|
+
#does uniqueness work?
|
248
|
+
Resque.enqueue(UniqueJob, {:_id => 'my_id', :arg1=> 'my args1'})
|
249
|
+
assert_equal(1, Resque.size(:unique))
|
250
|
+
assert_equal('my args1', Resque.peek(:unique)['args'][0]['arg1'])
|
251
|
+
assert_equal('my_id', Resque.peek(:unique)['args'][0]['_id'])
|
252
|
+
Resque.enqueue(UniqueJob, {:_id => 'my_id', :arg1=> 'my args2'})
|
253
|
+
assert_equal(1, Resque.size(:unique))
|
254
|
+
assert_equal('my args2', Resque.peek(:unique)['args'][0]['arg1'])
|
255
|
+
|
256
|
+
#if I enqueue unique jobs with the same key in 2 queues, do I get 2 jobs?
|
257
|
+
Resque.enqueue(UniqueJob, {:_id => 'my_id3', :arg1=> 'my arg3'})
|
258
|
+
assert_equal(2, Resque.size(:unique))
|
259
|
+
Resque.enqueue(OtherUnique, {:_id => 'my_id3', :arg1=> 'my args4'})
|
260
|
+
#following line fails because :unique and :unique2 are in the same collection
|
261
|
+
#\assert_equal(2, Resque.size(:unique))
|
262
|
+
assert_equal(1, Resque.size(:unique2))
|
263
|
+
|
264
|
+
#can I enqueue normal jobs in the unique queue?
|
265
|
+
Resque.enqueue(NonUnique, {:arg1=> 'my args'})
|
266
|
+
assert_equal(3, Resque.size(:unique))
|
267
|
+
Resque.enqueue(NonUnique, {:_id => 'my_id', :_id => 'my_id', :arg1=> 'my args2'})
|
268
|
+
assert_equal(4, Resque.size(:unique))
|
269
|
+
|
270
|
+
#how do unique jobs work without a given _id?
|
271
|
+
Resque.enqueue(UniqueJob, {:arg1=> 'my args3'})
|
272
|
+
assert_equal(5, Resque.size(:unique))
|
273
|
+
assert_equal('my args3', Resque.peek(:unique, 4)['args'][0]['arg1'])
|
274
|
+
Resque.enqueue(UniqueJob, {:arg1=> 'my args4'})
|
275
|
+
assert_equal(6, Resque.size(:unique))
|
276
|
+
assert_equal('my args4', Resque.peek(:unique, 5)['args'][0]['arg1'])
|
277
|
+
end
|
278
|
+
|
279
|
+
test "Can bypass queues for testing" do
|
280
|
+
Resque.enqueue(NonUnique, 'test')
|
281
|
+
assert_equal(1, Resque.size(:unique))
|
282
|
+
Resque.bypass_queues = true
|
283
|
+
Resque.enqueue(NonUnique, 'test')
|
284
|
+
assert_equal(1, Resque.size(:unique))
|
285
|
+
Resque.bypass_queues = false
|
286
|
+
Resque.enqueue(NonUnique, 'test')
|
287
|
+
assert_equal(2, Resque.size(:unique))
|
288
|
+
end
|
289
|
+
|
290
|
+
test "delayed jobs work" do
|
291
|
+
args = { :delay_until => Time.new-1}
|
292
|
+
Resque.enqueue(DelayedJob, args)
|
293
|
+
job = Resque::Job.reserve(:delayed)
|
294
|
+
assert_equal(1, job.args[0].keys.length)
|
295
|
+
assert_equal(args[:delay_until].to_i, job.args[0]["delay_until"].to_i)
|
296
|
+
args[:delay_until] = Time.new + 2
|
297
|
+
assert_equal(0, Resque.delayed_size(:delayed))
|
298
|
+
Resque.enqueue(DelayedJob, args)
|
299
|
+
|
300
|
+
assert_equal(1, Resque.delayed_size(:delayed))
|
301
|
+
assert_nil Resque.peek(:delayed)
|
302
|
+
assert_nil Resque::Job.reserve(:delayed)
|
303
|
+
sleep 1
|
304
|
+
assert_nil Resque::Job.reserve(:delayed)
|
305
|
+
sleep 1
|
306
|
+
assert_equal(DelayedJob, Resque::Job.reserve(:delayed).payload_class)
|
307
|
+
end
|
308
|
+
|
309
|
+
test "delayed unique jobs modify args in place" do
|
310
|
+
args = { :delay_until => Time.new + 3600, :_id => 'unique'}
|
311
|
+
Resque.enqueue(DelayedJob, args)
|
312
|
+
assert_nil(Resque.peek(:delayed))
|
313
|
+
args[:delay_until] = Time.new - 1
|
314
|
+
Resque.enqueue(DelayedJob, args)
|
315
|
+
assert_equal(2, Resque::Job.reserve(:delayed).args[0].keys.count)
|
316
|
+
end
|
317
|
+
|
318
|
+
test "delayed attribute is ignored when bypassing queues" do
|
319
|
+
Resque.bypass_queues = true
|
320
|
+
args = { :delay_until => Time.new+20}
|
321
|
+
foo = Resque.enqueue(DelayedJob, args)
|
322
|
+
assert(0, Resque.size(:delayed))
|
323
|
+
assert(args[:delay_until] > Time.new)
|
324
|
+
assert(foo =~ /^delayed job executing/)
|
325
|
+
Resque.bypass_queues = false
|
326
|
+
end
|
327
|
+
|
328
|
+
test "other queues are not affected" do
|
329
|
+
args = { :delay_until => Time.new+10}
|
330
|
+
assert OtherUnique.instance_variable_get :@delayed_jobs
|
331
|
+
Resque.enqueue(OtherUnique, args)
|
332
|
+
job = Resque::Job.reserve(:unique2)
|
333
|
+
assert_equal(1, job.args[0].keys.length)
|
334
|
+
end
|
335
|
+
|
336
|
+
test "can enqueue normal jobs in a delayed queue" do
|
337
|
+
args = { :delay_until => Time.new + 3600}
|
338
|
+
Resque.enqueue(DelayedJob, args)
|
339
|
+
Resque.enqueue(DelayedJob, args)
|
340
|
+
Resque.enqueue(DelayedJob, args)
|
341
|
+
assert_equal(3, Resque.size(:delayed))
|
342
|
+
assert_equal(3, Resque.delayed_size(:delayed))
|
343
|
+
assert_equal(0, Resque.ready_size(:delayed))
|
344
|
+
Resque.enqueue(NonDelayedJob, args)
|
345
|
+
Resque.enqueue(NonDelayedJob, args)
|
346
|
+
Resque.enqueue(DelayedJob, args)
|
347
|
+
assert_equal(6, Resque.size(:delayed))
|
348
|
+
assert_equal(2, Resque.ready_size(:delayed))
|
349
|
+
assert_equal(4, Resque.delayed_size(:delayed))
|
350
|
+
end
|
351
|
+
end
|