job_boss 0.5.7 → 0.5.8
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/job_boss.gemspec +1 -1
- data/lib/job_boss/job.rb +16 -11
- data/lib/job_boss/queuer.rb +14 -14
- data/test/app_root/app/models/sleep.rb +7 -0
- data/test/app_root/config/environment.rb +1 -0
- data/test/unit/job_test.rb +10 -0
- metadata +5 -3
data/job_boss.gemspec
CHANGED
data/lib/job_boss/job.rb
CHANGED
@@ -199,21 +199,26 @@ private
|
|
199
199
|
raise ArgumentError, "Invalid path (must have #)" unless path.match(/.#./)
|
200
200
|
controller, action = path.split('#')
|
201
201
|
|
202
|
-
|
203
|
-
|
202
|
+
controller_objects = []
|
203
|
+
begin
|
204
|
+
controller_objects << Kernel.const_get("#{controller.classify}Jobs").new
|
204
205
|
rescue NameError
|
205
|
-
begin
|
206
|
-
Kernel.const_get("#{controller.classify}")
|
207
|
-
rescue NameError
|
208
|
-
raise ArgumentError, "Invalid controller: #{controller}"
|
209
|
-
end
|
210
206
|
end
|
211
|
-
|
212
|
-
|
213
|
-
|
207
|
+
|
208
|
+
begin
|
209
|
+
controller_objects << Kernel.const_get("#{controller.classify}")
|
210
|
+
rescue NameError
|
211
|
+
end
|
212
|
+
|
213
|
+
raise ArgumentError, "Invalid controller: #{controller}" if controller_objects.empty?
|
214
|
+
|
215
|
+
controller_object = controller_objects.detect {|controller_object| controller_object.respond_to?(action) }
|
216
|
+
|
217
|
+
raise ArgumentError, "Invalid path action: #{action}" if !controller_object
|
218
|
+
|
214
219
|
controller_object.send(action, *args)
|
215
220
|
end
|
216
|
-
|
221
|
+
|
217
222
|
def pending_paths
|
218
223
|
self.pending.except(:order).select('DISTINCT path').collect(&:path)
|
219
224
|
end
|
data/lib/job_boss/queuer.rb
CHANGED
@@ -6,10 +6,11 @@ module JobBoss
|
|
6
6
|
|
7
7
|
method_name = method_id.id2name
|
8
8
|
|
9
|
-
if @
|
9
|
+
if @classes && @controller
|
10
10
|
# In here, we've already figured out the class, so assume the method_missing call is to the method
|
11
|
+
actionable_class = @classes.detect {|controller_class| controller_class.respond_to?(method_name) }
|
11
12
|
|
12
|
-
if
|
13
|
+
if actionable_class
|
13
14
|
require 'job_boss/job'
|
14
15
|
path = "#{@controller}##{method_name}"
|
15
16
|
|
@@ -23,22 +24,21 @@ module JobBoss
|
|
23
24
|
end
|
24
25
|
else
|
25
26
|
# Check to see if there's a class
|
27
|
+
@classes = []
|
26
28
|
begin
|
27
|
-
|
28
|
-
@class = Kernel.const_get("#{method_name.classify}Jobs").new
|
29
|
-
|
30
|
-
@controller = method_name
|
29
|
+
@classes << Kernel.const_get("#{method_name.classify}Jobs").new
|
31
30
|
rescue NameError
|
32
|
-
begin
|
33
|
-
# If we don't find a class that ends in "Jobs", we're going to call a class method
|
34
|
-
@class = Kernel.const_get("#{method_name.classify}")
|
35
|
-
|
36
|
-
@controller = method_name
|
37
|
-
rescue
|
38
|
-
raise ArgumentError, "Invalid controller"
|
39
|
-
end
|
40
31
|
end
|
41
32
|
|
33
|
+
begin
|
34
|
+
@classes << Kernel.const_get("#{method_name.classify}")
|
35
|
+
rescue
|
36
|
+
end
|
37
|
+
|
38
|
+
raise ArgumentError, "Invalid controller" if @classes.blank?
|
39
|
+
|
40
|
+
@controller = method_name
|
41
|
+
|
42
42
|
self
|
43
43
|
end
|
44
44
|
end
|
data/test/unit/job_test.rb
CHANGED
@@ -91,6 +91,16 @@ class DaemonTest < ActiveSupport::TestCase
|
|
91
91
|
assert_equal "I can't not do that, Dave.", error.message
|
92
92
|
assert_equal Array, error.backtrace.class
|
93
93
|
|
94
|
+
|
95
|
+
|
96
|
+
# Test calling method where there is both a Sleep model and a SleepJobs class
|
97
|
+
job = Boss.queue.sleep.add_snoozes(2, 5)
|
98
|
+
|
99
|
+
Job.wait_for_jobs(job)
|
100
|
+
|
101
|
+
assert_equal 7, job.result
|
102
|
+
|
103
|
+
|
94
104
|
stop_daemon
|
95
105
|
end
|
96
106
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 8
|
9
|
+
version: 0.5.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Brian Underwood
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-20 00:00:00 -05:00
|
18
18
|
default_executable: job_boss
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- test/app_root/app/jobs/sleep_jobs.rb
|
145
145
|
- test/app_root/app/jobs/string_jobs.rb
|
146
146
|
- test/app_root/app/models/penguin.rb
|
147
|
+
- test/app_root/app/models/sleep.rb
|
147
148
|
- test/app_root/config/database.yml
|
148
149
|
- test/app_root/config/environment.rb
|
149
150
|
- test/test_helper.rb
|
@@ -190,6 +191,7 @@ test_files:
|
|
190
191
|
- test/app_root/app/jobs/sleep_jobs.rb
|
191
192
|
- test/app_root/app/jobs/string_jobs.rb
|
192
193
|
- test/app_root/app/models/penguin.rb
|
194
|
+
- test/app_root/app/models/sleep.rb
|
193
195
|
- test/app_root/config/database.yml
|
194
196
|
- test/app_root/config/environment.rb
|
195
197
|
- test/test_helper.rb
|