resque_unit 0.3.4 → 0.3.5
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/lib/resque_unit/resque.rb +1 -0
- data/lib/resque_unit/scheduler.rb +9 -0
- data/test/resque_unit_scheduler_test.rb +63 -1
- data/test/resque_unit_test.rb +5 -1
- metadata +5 -5
data/lib/resque_unit/resque.rb
CHANGED
@@ -22,6 +22,15 @@ module ResqueUnit
|
|
22
22
|
enqueue_unit(queue_for(klass), {:klass => klass, :args => decode(encode(args)), :timestamp => timestamp})
|
23
23
|
end
|
24
24
|
|
25
|
+
def remove_delayed(klass, *args)
|
26
|
+
queue = Resque.queue(queue_for(klass))
|
27
|
+
if args # retrieve the elements that match klass and args in the queue
|
28
|
+
args = Resque.normalized_args(args)
|
29
|
+
queue.delete_if { |e| e[:klass] == klass && e[:args] == args }
|
30
|
+
else # if no args were passed, retrieve all queued jobs that match klass
|
31
|
+
queue.delete_if {|e| e[:klass] == klass}
|
32
|
+
end
|
33
|
+
end
|
25
34
|
end
|
26
35
|
|
27
36
|
Resque.send(:extend, Scheduler)
|
@@ -27,6 +27,20 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
|
|
27
27
|
assert_not_queued_in(300, MediumPriorityJob)
|
28
28
|
end
|
29
29
|
|
30
|
+
context "and then the job is removed with #remove_delayed" do
|
31
|
+
setup do
|
32
|
+
Resque.remove_delayed(MediumPriorityJob)
|
33
|
+
end
|
34
|
+
should "pass the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
|
35
|
+
assert_not_queued_at(300, MediumPriorityJob)
|
36
|
+
end
|
37
|
+
|
38
|
+
should "fail the assert_queued_at(@time, MediumPriorityJob) assertion" do
|
39
|
+
assert_raise Test::Unit::AssertionFailedError do
|
40
|
+
assert_queued_at(300, MediumPriorityJob)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
30
44
|
end
|
31
45
|
|
32
46
|
context "A task that schedules a resque job in 5 minutes with arguments" do
|
@@ -44,6 +58,40 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
|
|
44
58
|
assert_queued_in(600, JobWithArguments, [2, 'test'])
|
45
59
|
end
|
46
60
|
end
|
61
|
+
|
62
|
+
context "and then the job is removed with #remove_delayed" do
|
63
|
+
setup do
|
64
|
+
Resque.remove_delayed(JobWithArguments, 1, 'test')
|
65
|
+
end
|
66
|
+
should "pass the assert_not_queued_at(@time, JobWithArguments, 1, 'test') assertion" do
|
67
|
+
assert_not_queued_at(600, JobWithArguments, 1, 'test')
|
68
|
+
end
|
69
|
+
|
70
|
+
should "fail the assert_queued_at(@time, JobWithArguments, 1, 'test') assertion" do
|
71
|
+
assert_raise Test::Unit::AssertionFailedError do
|
72
|
+
assert_queued_at(600, JobWithArguments, 1, 'test')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "and a job of the same class but with different arguments is removed with #remove_delayed" do
|
78
|
+
setup do
|
79
|
+
Resque.remove_delayed(JobWithArguments, 2, 'test')
|
80
|
+
end
|
81
|
+
should "still pass the assert_queued_in(600, JobWithArguments) assertion" do
|
82
|
+
assert_queued_in(600, JobWithArguments)
|
83
|
+
end
|
84
|
+
|
85
|
+
should "still pass the assert_queued_in(600, JobWithArguments, [1, 'test']) assertion" do
|
86
|
+
assert_queued_in(600, JobWithArguments, [1, 'test'])
|
87
|
+
end
|
88
|
+
|
89
|
+
should "still fail the assert_queued_in(600, JobWithArguments, [2, 'test']) assertion" do
|
90
|
+
assert_raise Test::Unit::AssertionFailedError do
|
91
|
+
assert_queued_in(600, JobWithArguments, [2, 'test'])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
47
95
|
end
|
48
96
|
|
49
97
|
context "A task that schedules a resque job on Sept. 6, 2016 at 6am" do
|
@@ -65,6 +113,20 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
|
|
65
113
|
should "pass the assert_not_queued_at(@time - 100, MediumPriorityJob) assertion" do
|
66
114
|
assert_not_queued_at(@time - 100, MediumPriorityJob)
|
67
115
|
end
|
68
|
-
end
|
69
116
|
|
117
|
+
context "and then the job is removed with #remove_delayed" do
|
118
|
+
setup do
|
119
|
+
Resque.remove_delayed(MediumPriorityJob)
|
120
|
+
end
|
121
|
+
should "pass the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
|
122
|
+
assert_not_queued_at(@time, MediumPriorityJob)
|
123
|
+
end
|
124
|
+
|
125
|
+
should "fail the assert_queued_at(@time, MediumPriorityJob) assertion" do
|
126
|
+
assert_raise Test::Unit::AssertionFailedError do
|
127
|
+
assert_queued_at(@time, MediumPriorityJob)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
70
132
|
end
|
data/test/resque_unit_test.rb
CHANGED
@@ -18,7 +18,11 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
18
18
|
|
19
19
|
context "A task that schedules a resque job" do
|
20
20
|
setup do
|
21
|
-
Resque.enqueue(LowPriorityJob)
|
21
|
+
@returned = Resque.enqueue(LowPriorityJob)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'return a value that evaluates to true' do
|
25
|
+
assert @returned
|
22
26
|
end
|
23
27
|
|
24
28
|
should "pass the assert_queued(job) assertion" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 5
|
9
|
+
version: 0.3.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Justin Weiss
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-24 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -95,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
95
|
requirements:
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
|
-
hash:
|
98
|
+
hash: -3582999941534003168
|
99
99
|
segments:
|
100
100
|
- 0
|
101
101
|
version: "0"
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
requirements:
|
105
105
|
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
hash:
|
107
|
+
hash: -3582999941534003168
|
108
108
|
segments:
|
109
109
|
- 0
|
110
110
|
version: "0"
|