resque_unit 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -208,7 +208,7 @@ module Resque
208
208
 
209
209
  # If an exception occurs during the job execution, look for an
210
210
  # on_failure hook then re-raise.
211
- rescue => e
211
+ rescue Object => e
212
212
  failure_hooks.each { |hook| job_class.send(hook, e, *job_payload["args"]) }
213
213
  raise e
214
214
  end
@@ -217,7 +217,7 @@ module Resque
217
217
  class Job
218
218
  extend Helpers
219
219
  def self.create(queue, klass_name, *args)
220
- Resque.enqueue_unit(queue, {"class" => constantize(klass_name), "args" => args})
220
+ Resque.enqueue_unit(queue, {"class" => constantize(klass_name).to_s, "args" => args})
221
221
  end
222
222
  end
223
223
 
@@ -19,7 +19,7 @@ module ResqueUnit
19
19
  end
20
20
 
21
21
  def enqueue_with_timestamp(timestamp, klass, *args)
22
- enqueue_unit(queue_for(klass), {"class" => klass, "args" => args, "timestamp" => timestamp})
22
+ enqueue_unit(queue_for(klass), {"class" => klass.name, "args" => args, "timestamp" => timestamp})
23
23
  end
24
24
 
25
25
  def remove_delayed(klass, *args)
@@ -28,6 +28,12 @@ module ResqueUnit
28
28
  args ||= []
29
29
  encoded_job_payloads.delete_if { |e| e = Resque.decode(e); e["class"] == klass.to_s && e["args"] == args }
30
30
  end
31
+
32
+ def remove_delayed_job_from_timestamp(timestamp, klass, *args)
33
+ encoded_job_payloads = Resque.queue(queue_for(klass))
34
+ args ||= []
35
+ encoded_job_payloads.delete_if { |e| e = Resque.decode(e); e["class"] == klass.to_s && e["timestamp"] == timestamp.to_s && e["args"] == args }
36
+ end
31
37
  end
32
38
 
33
39
  Resque.send(:extend, Scheduler)
@@ -18,12 +18,12 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  should "fail the assert_queued_in(300, job) assertion" do
21
- assert_raise Test::Unit::AssertionFailedError do
21
+ assert_raise Test::Unit::AssertionFailedError do
22
22
  assert_queued_in(300, MediumPriorityJob)
23
23
  end
24
24
  end
25
25
 
26
- should "pass the assert_not_queued_in(300, job) assertion" do
26
+ should "pass the assert_not_queued_in(300, job) assertion" do
27
27
  assert_not_queued_in(300, MediumPriorityJob)
28
28
  end
29
29
 
@@ -31,7 +31,7 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
31
31
  setup do
32
32
  Resque.remove_delayed(MediumPriorityJob)
33
33
  end
34
- should "pass the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
34
+ should "pass the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
35
35
  assert_not_queued_at(300, MediumPriorityJob)
36
36
  end
37
37
 
@@ -42,7 +42,7 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
42
42
  end
43
43
  end
44
44
  end
45
-
45
+
46
46
  context "A task that schedules a resque job in 5 minutes with arguments" do
47
47
  setup { Resque.enqueue_in(600, JobWithArguments, 1, "test") }
48
48
  should "pass the assert_queued_in(600, JobWithArguments) assertion" do
@@ -53,8 +53,8 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
53
53
  assert_queued_in(600, JobWithArguments, [1, 'test'])
54
54
  end
55
55
 
56
- should "fail the assert_queued_in(600, JobWithArguments, [2, 'test']) assertion" do
57
- assert_raise Test::Unit::AssertionFailedError do
56
+ should "fail the assert_queued_in(600, JobWithArguments, [2, 'test']) assertion" do
57
+ assert_raise Test::Unit::AssertionFailedError do
58
58
  assert_queued_in(600, JobWithArguments, [2, 'test'])
59
59
  end
60
60
  end
@@ -63,7 +63,7 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
63
63
  setup do
64
64
  Resque.remove_delayed(JobWithArguments, 1, 'test')
65
65
  end
66
- should "pass the assert_not_queued_at(@time, JobWithArguments, 1, 'test') assertion" do
66
+ should "pass the assert_not_queued_at(@time, JobWithArguments, 1, 'test') assertion" do
67
67
  assert_not_queued_at(600, JobWithArguments, 1, 'test')
68
68
  end
69
69
 
@@ -86,26 +86,26 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
86
86
  assert_queued_in(600, JobWithArguments, [1, 'test'])
87
87
  end
88
88
 
89
- should "still fail the assert_queued_in(600, JobWithArguments, [2, 'test']) assertion" do
90
- assert_raise Test::Unit::AssertionFailedError do
89
+ should "still fail the assert_queued_in(600, JobWithArguments, [2, 'test']) assertion" do
90
+ assert_raise Test::Unit::AssertionFailedError do
91
91
  assert_queued_in(600, JobWithArguments, [2, 'test'])
92
92
  end
93
93
  end
94
94
  end
95
95
  end
96
-
96
+
97
97
  context "A task that schedules a resque job on Sept. 6, 2016 at 6am" do
98
98
  setup do
99
99
  @time = Time.mktime(2016, 9, 6, 6)
100
100
  Resque.enqueue_at(@time, MediumPriorityJob)
101
101
  end
102
102
 
103
- should "pass the assert_queued_at(@time, MediumPriorityJob) assertion" do
103
+ should "pass the assert_queued_at(@time, MediumPriorityJob) assertion" do
104
104
  assert_queued_at(@time, MediumPriorityJob)
105
105
  end
106
106
 
107
- should "fail the assert_queued_at(@time - 100, MediumPriorityJob) assertion" do
108
- assert_raise Test::Unit::AssertionFailedError do
107
+ should "fail the assert_queued_at(@time - 100, MediumPriorityJob) assertion" do
108
+ assert_raise Test::Unit::AssertionFailedError do
109
109
  assert_queued_at(@time - 100, MediumPriorityJob)
110
110
  end
111
111
  end
@@ -118,7 +118,7 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
118
118
  setup do
119
119
  Resque.remove_delayed(MediumPriorityJob)
120
120
  end
121
- should "pass the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
121
+ should "pass the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
122
122
  assert_not_queued_at(@time, MediumPriorityJob)
123
123
  end
124
124
 
@@ -128,5 +128,74 @@ class ResqueUnitSchedulerTest < Test::Unit::TestCase
128
128
  end
129
129
  end
130
130
  end
131
+
132
+ context "and then the job is removed with #remove_delayed_job_with_timestamp" do
133
+ setup do
134
+ Resque.remove_delayed_job_from_timestamp(@time, MediumPriorityJob)
135
+ end
136
+
137
+ should "pass the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
138
+ assert_not_queued_at(@time, MediumPriorityJob)
139
+ end
140
+
141
+ should "fail the assert_queued_at(@time, MediumPriorityJob) assertion" do
142
+ assert_raise Test::Unit::AssertionFailedError do
143
+ assert_queued_at(@time, MediumPriorityJob)
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ context "A task that schedules a resque job with arguments on on Sept. 6, 2016 at 6am" do
150
+ setup do
151
+ @time = Time.mktime(2016, 9, 6, 6)
152
+ Resque.enqueue_at(@time, JobWithArguments, 1, "test")
153
+ end
154
+
155
+ should "pass the assert_queued_at(@time, JobWithArguments, *args) assertion" do
156
+ assert_queued_at(@time, JobWithArguments, [1, "test"])
157
+ end
158
+
159
+ should "fail the assert_queued_at(@time - 100, JobWithArguments, *args) assertion" do
160
+ assert_raise Test::Unit::AssertionFailedError do
161
+ assert_queued_at(@time - 100, JobWithArguments, [1, "test"])
162
+ end
163
+ end
164
+
165
+ should "pass the assert_not_queued_at(@time - 100, JobWithArguments, *args) assertion" do
166
+ assert_not_queued_at(@time - 100, JobWithArguments, [1, "test"])
167
+ end
168
+
169
+ context "and then the job is removed with #remove_delayed" do
170
+ setup do
171
+ Resque.remove_delayed(JobWithArguments, 1, "test")
172
+ end
173
+
174
+ should "pass the assert_not_queued_at(@time, JobWithArguments, *args) assertion" do
175
+ assert_not_queued_at(@time, JobWithArguments, [1, "test"])
176
+ end
177
+
178
+ should "fail the assert_queued_at(@time, JobWithArguments, *args) assertion" do
179
+ assert_raise Test::Unit::AssertionFailedError do
180
+ assert_queued_at(@time, JobWithArguments, [1, "test"])
181
+ end
182
+ end
183
+ end
184
+
185
+ context "and then the job is removed with #remove_delayed_job_from_timestamp" do
186
+ setup do
187
+ Resque.remove_delayed_job_from_timestamp(@time, JobWithArguments, 1, "test")
188
+ end
189
+
190
+ should "pass the assert_not_queued_at(@time, JobWithArguments, *args) assertion" do
191
+ assert_not_queued_at(@time, JobWithArguments, [1, "test"])
192
+ end
193
+
194
+ should "fail the assert_queued_at(@time, MediumPriorityJob, *args) assertion" do
195
+ assert_raise Test::Unit::AssertionFailedError do
196
+ assert_queued_at(@time, JobWithArguments, [1, "test"])
197
+ end
198
+ end
199
+ end
131
200
  end
132
201
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-14 00:00:00.000000000Z
12
+ date: 2012-03-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70242270906860 !ruby/object:Gem::Requirement
16
+ requirement: &70334013235640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.4.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70242270906860
24
+ version_requirements: *70334013235640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70242270906100 !ruby/object:Gem::Requirement
27
+ requirement: &70334013235240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70242270906100
35
+ version_requirements: *70334013235240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shoulda
38
- requirement: &70242270904960 !ruby/object:Gem::Requirement
38
+ requirement: &70334013234780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70242270904960
46
+ version_requirements: *70334013234780
47
47
  description:
48
48
  email: justin@uberweiss.org
49
49
  executables: []
@@ -80,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  segments:
82
82
  - 0
83
- hash: -2544515951238107368
83
+ hash: 504436930256171136
84
84
  required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
@@ -89,10 +89,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  segments:
91
91
  - 0
92
- hash: -2544515951238107368
92
+ hash: 504436930256171136
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 1.8.3
95
+ rubygems_version: 1.8.10
96
96
  signing_key:
97
97
  specification_version: 3
98
98
  summary: Test::Unit support for resque job queueing