resque_unit 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/resque_unit/resque.rb +23 -7
- data/test/resque_unit_test.rb +25 -1
- data/test/sample_jobs.rb +7 -0
- metadata +3 -3
data/lib/resque_unit/resque.rb
CHANGED
@@ -5,23 +5,29 @@ module Resque
|
|
5
5
|
# Resets all the queues to the empty state. This should be called in
|
6
6
|
# your test's +setup+ method until I can figure out a way for it to
|
7
7
|
# automatically be called.
|
8
|
-
|
9
|
-
|
8
|
+
#
|
9
|
+
# If <tt>queue_name</tt> is given, then resets only that queue.
|
10
|
+
def self.reset!(queue_name = nil)
|
11
|
+
if @queue && queue_name
|
12
|
+
@queue[queue_name] = []
|
13
|
+
else
|
14
|
+
@queue = Hash.new { |h, k| h[k] = [] }
|
15
|
+
end
|
10
16
|
end
|
11
17
|
|
12
18
|
# Returns an array of all the jobs that have been queued. Each
|
13
19
|
# element is of the form +{:klass => klass, :args => args}+ where
|
14
20
|
# +klass+ is the job's class and +args+ is an array of the arguments
|
15
21
|
# passed to the job.
|
16
|
-
def self.queue(
|
22
|
+
def self.queue(queue_name)
|
17
23
|
self.reset! unless @queue
|
18
|
-
@queue[
|
24
|
+
@queue[queue_name]
|
19
25
|
end
|
20
26
|
|
21
27
|
# Executes all jobs in all queues in an undefined order.
|
22
28
|
def self.run!
|
23
29
|
old_queue = @queue.dup
|
24
|
-
reset!
|
30
|
+
self.reset!
|
25
31
|
|
26
32
|
old_queue.each do |k, v|
|
27
33
|
while job = v.shift
|
@@ -30,10 +36,20 @@ module Resque
|
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
39
|
+
# Executes all jobs in the given queue in an undefined order.
|
40
|
+
def self.run_for!(queue_name)
|
41
|
+
jobs = self.queue(queue_name)
|
42
|
+
self.reset!(queue_name)
|
43
|
+
|
44
|
+
while job = jobs.shift
|
45
|
+
job[:klass].perform(*job[:args])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
33
49
|
# Returns the size of the given queue
|
34
|
-
def self.size(
|
50
|
+
def self.size(queue_name)
|
35
51
|
self.reset! unless @queue
|
36
|
-
@queue[
|
52
|
+
@queue[queue_name].length
|
37
53
|
end
|
38
54
|
|
39
55
|
# :nodoc:
|
data/test/resque_unit_test.rb
CHANGED
@@ -15,7 +15,7 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
15
15
|
assert_equal 1, Resque.queue(MediumPriorityJob.queue).length
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
context "A task that schedules a resque job" do
|
20
20
|
setup do
|
21
21
|
Resque.enqueue(LowPriorityJob)
|
@@ -137,6 +137,30 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
context "A task in a different queue" do
|
141
|
+
setup do
|
142
|
+
Resque.enqueue(LowPriorityJob)
|
143
|
+
Resque.enqueue(HighPriorityJob)
|
144
|
+
end
|
145
|
+
|
146
|
+
should "add a LowPriorityJob" do
|
147
|
+
assert_queued(LowPriorityJob)
|
148
|
+
end
|
149
|
+
|
150
|
+
should "add a HighPriorityJob" do
|
151
|
+
assert_queued(HighPriorityJob)
|
152
|
+
end
|
153
|
+
|
154
|
+
context ", when Resque.run_for! is called," do
|
155
|
+
should "run only tasks in the high priority queue" do
|
156
|
+
Resque.run_for!(Resque.queue_for(HighPriorityJob))
|
157
|
+
|
158
|
+
assert_queued(LowPriorityJob)
|
159
|
+
assert_not_queued(HighPriorityJob)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
140
164
|
context "An assertion message" do
|
141
165
|
context "of assert_queued" do
|
142
166
|
should "include job class and queue content" do
|
data/test/sample_jobs.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque_unit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 5
|
10
|
+
version: 0.2.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Justin Weiss
|