job_boss 0.5.5 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +7 -7
- data/doc/ActiveSupport/TestCase.html +2 -2
- data/doc/JobBoss/Boss.html +222 -221
- data/doc/JobBoss/Config.html +43 -43
- data/doc/JobBoss/Job.html +4 -4
- data/doc/JobBoss/Queuer.html +40 -39
- data/doc/created.rid +9 -9
- data/doc/index.html +4 -4
- data/doc/lib/job_boss/boss_rb.html +1 -1
- data/doc/lib/job_boss/config_rb.html +3 -1
- data/doc/lib/job_boss/job_rb.html +1 -1
- data/doc/lib/job_boss/queuer_rb.html +3 -1
- data/doc/lib/migrate_rb.html +1 -1
- data/doc/test/test_helper_rb.html +1 -1
- data/doc/test/unit/daemon_test_rb.html +1 -1
- data/doc/test/unit/job_test_rb.html +1 -1
- data/job_boss.gemspec +1 -1
- data/lib/job_boss/boss.rb +46 -41
- data/lib/job_boss/config.rb +16 -14
- data/lib/job_boss/job.rb +3 -3
- data/lib/job_boss/queuer.rb +1 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/daemon_test.rb +32 -5
- metadata +3 -3
data/doc/JobBoss/Config.html
CHANGED
@@ -309,50 +309,50 @@
|
|
309
309
|
<div class="method-source-code"
|
310
310
|
id="parse-args-source">
|
311
311
|
<pre>
|
312
|
-
<span class="ruby-comment cmt"># File lib/job_boss/config.rb, line
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
13:
|
322
|
-
14: <span class="ruby-identifier">require</span> <span class="ruby-value str">'optparse'</span>
|
312
|
+
<span class="ruby-comment cmt"># File lib/job_boss/config.rb, line 7</span>
|
313
|
+
7: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_args</span>(<span class="ruby-identifier">argv</span>, <span class="ruby-identifier">options</span> = {})
|
314
|
+
8: <span class="ruby-ivar">@application_root</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_APPLICATION_ROOT'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:working_dir</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">pwd</span>)
|
315
|
+
9: <span class="ruby-ivar">@database_yaml_path</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_DATABASE_YAML_PATH'</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'config/database.yml'</span>
|
316
|
+
10: <span class="ruby-ivar">@log_path</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_LOG_PATH'</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'log/job_boss.log'</span>
|
317
|
+
11: <span class="ruby-ivar">@jobs_path</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_JOBS_PATH'</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'app/jobs'</span>
|
318
|
+
12: <span class="ruby-ivar">@sleep_interval</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_SLEEP_INTERVAL'</span>].<span class="ruby-identifier">blank?</span> <span class="ruby-operator">?</span> <span class="ruby-value">0.5</span> <span class="ruby-operator">:</span> <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_SLEEP_INTERVAL'</span>].<span class="ruby-identifier">to_f</span>
|
319
|
+
13: <span class="ruby-ivar">@employee_limit</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_EMPLOYEE_LIMIT'</span>].<span class="ruby-identifier">blank?</span> <span class="ruby-operator">?</span> <span class="ruby-value">4</span> <span class="ruby-operator">:</span> <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_EMPLOYEE_LIMIT'</span>].<span class="ruby-identifier">to_i</span>
|
320
|
+
14: <span class="ruby-ivar">@environment</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_ENVIRONMENT'</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'development'</span>
|
323
321
|
15:
|
324
|
-
16: <span class="ruby-
|
325
|
-
17:
|
326
|
-
18:
|
327
|
-
19: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">
|
328
|
-
20:
|
329
|
-
21: <span class="ruby-keyword kw">
|
330
|
-
22:
|
331
|
-
23: <span class="ruby-
|
332
|
-
24:
|
333
|
-
25: <span class="ruby-keyword kw">
|
334
|
-
26:
|
335
|
-
27: <span class="ruby-
|
336
|
-
28:
|
337
|
-
29: <span class="ruby-keyword kw">
|
338
|
-
30:
|
339
|
-
31: <span class="ruby-
|
340
|
-
32:
|
341
|
-
33: <span class="ruby-keyword kw">
|
342
|
-
34:
|
343
|
-
35: <span class="ruby-
|
344
|
-
36:
|
345
|
-
37: <span class="ruby-keyword kw">
|
346
|
-
38:
|
347
|
-
39: <span class="ruby-
|
348
|
-
40:
|
349
|
-
41: <span class="ruby-keyword kw">
|
350
|
-
42:
|
351
|
-
43: <span class="ruby-
|
352
|
-
44:
|
353
|
-
45: <span class="ruby-keyword kw">
|
354
|
-
46:
|
355
|
-
47:
|
322
|
+
16: <span class="ruby-identifier">require</span> <span class="ruby-value str">'optparse'</span>
|
323
|
+
17:
|
324
|
+
18: <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
|
325
|
+
19: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-value str">"Usage: job_boss [start|stop|restart|run|zap] [-- <options>]"</span>
|
326
|
+
20:
|
327
|
+
21: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-r"</span>, <span class="ruby-value str">"--application-root PATH"</span>, <span class="ruby-value str">"Path for the application root upon which other paths depend (defaults to .) Environment variable: JB_APPLICATION_ROOT"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
|
328
|
+
22: <span class="ruby-ivar">@application_root</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">path</span>)
|
329
|
+
23: <span class="ruby-keyword kw">end</span>
|
330
|
+
24:
|
331
|
+
25: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-d"</span>, <span class="ruby-value str">"--database-yaml PATH"</span>, <span class="ruby-node">"Path for database YAML (defaults to <application-root>/#{@database_yaml_path}) Environment variable: JB_DATABASE_YAML_PATH"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
|
332
|
+
26: <span class="ruby-ivar">@database_yaml_path</span> = <span class="ruby-identifier">path</span>
|
333
|
+
27: <span class="ruby-keyword kw">end</span>
|
334
|
+
28:
|
335
|
+
29: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-l"</span>, <span class="ruby-value str">"--log-path PATH"</span>, <span class="ruby-node">"Path for log file (defaults to <application-root>/#{@log_path}) Environment variable: JB_LOG_PATH"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
|
336
|
+
30: <span class="ruby-ivar">@log_path</span> = <span class="ruby-identifier">path</span>
|
337
|
+
31: <span class="ruby-keyword kw">end</span>
|
338
|
+
32:
|
339
|
+
33: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-j"</span>, <span class="ruby-value str">"--jobs-path PATH"</span>, <span class="ruby-node">"Path to folder with job classes (defaults to <application-root>/#{@jobs_path}) Environment variable: JB_JOBS_PATH"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
|
340
|
+
34: <span class="ruby-ivar">@jobs_path</span> = <span class="ruby-identifier">path</span>
|
341
|
+
35: <span class="ruby-keyword kw">end</span>
|
342
|
+
36:
|
343
|
+
37: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-e"</span>, <span class="ruby-value str">"--environment ENV"</span>, <span class="ruby-node">"Environment to use in database YAML file (defaults to '#{@environment}') Environment variable: JB_ENVIRONMENT"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">env</span><span class="ruby-operator">|</span>
|
344
|
+
38: <span class="ruby-ivar">@environment</span> = <span class="ruby-identifier">env</span>
|
345
|
+
39: <span class="ruby-keyword kw">end</span>
|
346
|
+
40:
|
347
|
+
41: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-s"</span>, <span class="ruby-value str">"--sleep-interval INTERVAL"</span>, <span class="ruby-constant">Integer</span>, <span class="ruby-node">"Number of seconds for the boss to sleep between checks of the queue (default #{@sleep_interval}) Environment variable: JB_SLEEP_INTERVAL"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">interval</span><span class="ruby-operator">|</span>
|
348
|
+
42: <span class="ruby-ivar">@sleep_interval</span> = <span class="ruby-identifier">interval</span>
|
349
|
+
43: <span class="ruby-keyword kw">end</span>
|
350
|
+
44:
|
351
|
+
45: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-c"</span>, <span class="ruby-value str">"--employee-limit LIMIT"</span>, <span class="ruby-constant">Integer</span>, <span class="ruby-value str">"Maximum number of employees (default 4) Environment variable: JB_EMPLOYEE_LIMIT"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">limit</span><span class="ruby-operator">|</span>
|
352
|
+
46: <span class="ruby-ivar">@employee_limit</span> = <span class="ruby-identifier">limit</span>
|
353
|
+
47: <span class="ruby-keyword kw">end</span>
|
354
|
+
48: <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">argv</span>)
|
355
|
+
49: <span class="ruby-keyword kw">end</span></pre>
|
356
356
|
</div>
|
357
357
|
|
358
358
|
</div>
|
data/doc/JobBoss/Job.html
CHANGED
@@ -586,7 +586,7 @@ Is the job complete?
|
|
586
586
|
<div class="method-heading">
|
587
587
|
|
588
588
|
<span class="method-name">dispatch</span><span
|
589
|
-
class="method-args">()</span>
|
589
|
+
class="method-args">(boss)</span>
|
590
590
|
<span class="method-click-advice">click to toggle source</span>
|
591
591
|
|
592
592
|
</div>
|
@@ -603,9 +603,9 @@ Method used by the boss to dispatch an employee
|
|
603
603
|
id="dispatch-source">
|
604
604
|
<pre>
|
605
605
|
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 15</span>
|
606
|
-
15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dispatch</span>
|
606
|
+
15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dispatch</span>(<span class="ruby-identifier">boss</span>)
|
607
607
|
16: <span class="ruby-identifier">mark_as_started</span>
|
608
|
-
17: <span class="ruby-
|
608
|
+
17: <span class="ruby-identifier">boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">"Dispatching Job ##{self.id}"</span>
|
609
609
|
18:
|
610
610
|
19: <span class="ruby-identifier">pid</span> = <span class="ruby-identifier">fork</span> <span class="ruby-keyword kw">do</span>
|
611
611
|
20: <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">reconnect!</span>
|
@@ -620,7 +620,7 @@ Method used by the boss to dispatch an employee
|
|
620
620
|
29: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">update_attribute</span>(<span class="ruby-value">:result</span>, <span class="ruby-identifier">value</span>)
|
621
621
|
30: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">exception</span>
|
622
622
|
31: <span class="ruby-identifier">mark_exception</span>(<span class="ruby-identifier">exception</span>)
|
623
|
-
32: <span class="ruby-
|
623
|
+
32: <span class="ruby-identifier">boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span> <span class="ruby-node">"Error running job ##{self.id}!"</span>
|
624
624
|
33: <span class="ruby-keyword kw">ensure</span>
|
625
625
|
34: <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">mark_as_completed</span>
|
626
626
|
35: <span class="ruby-identifier">sleep</span>(<span class="ruby-value">1</span>)
|
data/doc/JobBoss/Queuer.html
CHANGED
@@ -187,45 +187,46 @@
|
|
187
187
|
<span class="ruby-comment cmt"># File lib/job_boss/queuer.rb, line 3</span>
|
188
188
|
3: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">method_id</span>, *<span class="ruby-identifier">args</span>)
|
189
189
|
4: <span class="ruby-identifier">require</span> <span class="ruby-value str">'active_support'</span>
|
190
|
-
5:
|
191
|
-
6:
|
192
|
-
7:
|
193
|
-
8:
|
194
|
-
9:
|
195
|
-
10:
|
196
|
-
11:
|
197
|
-
12:
|
198
|
-
13: <span class="ruby-identifier">
|
199
|
-
14:
|
200
|
-
15:
|
201
|
-
16: <span class="ruby-ivar">@
|
202
|
-
17:
|
203
|
-
18:
|
204
|
-
19:
|
205
|
-
20:
|
206
|
-
21:
|
207
|
-
22:
|
208
|
-
23:
|
209
|
-
24:
|
210
|
-
25: <span class="ruby-
|
211
|
-
26:
|
212
|
-
27: <span class="ruby-
|
213
|
-
28:
|
214
|
-
29:
|
215
|
-
30:
|
216
|
-
31:
|
217
|
-
32:
|
218
|
-
33: <span class="ruby-
|
219
|
-
34:
|
220
|
-
35:
|
221
|
-
36:
|
222
|
-
37:
|
223
|
-
38:
|
224
|
-
39:
|
225
|
-
40:
|
226
|
-
41:
|
227
|
-
42:
|
228
|
-
43:
|
190
|
+
5: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/job'</span>
|
191
|
+
6:
|
192
|
+
7: <span class="ruby-identifier">method_name</span> = <span class="ruby-identifier">method_id</span>.<span class="ruby-identifier">id2name</span>
|
193
|
+
8:
|
194
|
+
9: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@class</span> <span class="ruby-operator">&&</span> <span class="ruby-ivar">@controller</span>
|
195
|
+
10: <span class="ruby-comment cmt"># In here, we've already figured out the class, so assume the method_missing call is to the method</span>
|
196
|
+
11:
|
197
|
+
12: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@class</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">method_name</span>)
|
198
|
+
13: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/job'</span>
|
199
|
+
14: <span class="ruby-identifier">path</span> = <span class="ruby-node">"#{@controller}##{method_name}"</span>
|
200
|
+
15:
|
201
|
+
16: <span class="ruby-ivar">@class</span> = <span class="ruby-keyword kw">nil</span>
|
202
|
+
17: <span class="ruby-ivar">@controller</span> = <span class="ruby-keyword kw">nil</span>
|
203
|
+
18:
|
204
|
+
19: <span class="ruby-constant">Job</span>.<span class="ruby-identifier">create</span>(<span class="ruby-value">:path</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">path</span>,
|
205
|
+
20: <span class="ruby-value">:args</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>)
|
206
|
+
21: <span class="ruby-keyword kw">else</span>
|
207
|
+
22: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"Invalid action"</span>
|
208
|
+
23: <span class="ruby-keyword kw">end</span>
|
209
|
+
24: <span class="ruby-keyword kw">else</span>
|
210
|
+
25: <span class="ruby-comment cmt"># Check to see if there's a class</span>
|
211
|
+
26: <span class="ruby-keyword kw">begin</span>
|
212
|
+
27: <span class="ruby-comment cmt"># If we find a class that ends in "Jobs", we instanciate it and call an instance method</span>
|
213
|
+
28: <span class="ruby-ivar">@class</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-node">"#{method_name.classify}Jobs"</span>).<span class="ruby-identifier">new</span>
|
214
|
+
29:
|
215
|
+
30: <span class="ruby-ivar">@controller</span> = <span class="ruby-identifier">method_name</span>
|
216
|
+
31: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
|
217
|
+
32: <span class="ruby-keyword kw">begin</span>
|
218
|
+
33: <span class="ruby-comment cmt"># If we don't find a class that ends in "Jobs", we're going to call a class method</span>
|
219
|
+
34: <span class="ruby-ivar">@class</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-node">"#{method_name.classify}"</span>)
|
220
|
+
35:
|
221
|
+
36: <span class="ruby-ivar">@controller</span> = <span class="ruby-identifier">method_name</span>
|
222
|
+
37: <span class="ruby-keyword kw">rescue</span>
|
223
|
+
38: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"Invalid controller"</span>
|
224
|
+
39: <span class="ruby-keyword kw">end</span>
|
225
|
+
40: <span class="ruby-keyword kw">end</span>
|
226
|
+
41:
|
227
|
+
42: <span class="ruby-keyword kw">self</span>
|
228
|
+
43: <span class="ruby-keyword kw">end</span>
|
229
|
+
44: <span class="ruby-keyword kw">end</span></pre>
|
229
230
|
</div>
|
230
231
|
|
231
232
|
</div>
|
data/doc/created.rid
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
|
1
|
+
Sun, 12 Dec 2010 13:52:00 -0500
|
2
2
|
./bin/job_boss Sat, 11 Dec 2010 15:09:03 -0500
|
3
3
|
./Gemfile Mon, 29 Nov 2010 09:41:29 -0500
|
4
4
|
./init.rb Fri, 03 Dec 2010 08:33:46 -0500
|
5
|
-
./lib/job_boss/boss.rb
|
5
|
+
./lib/job_boss/boss.rb Sun, 12 Dec 2010 13:46:34 -0500
|
6
6
|
./lib/job_boss/capistrano.rb Wed, 24 Nov 2010 14:13:12 -0500
|
7
|
-
./lib/job_boss/config.rb
|
8
|
-
./lib/job_boss/job.rb
|
9
|
-
./lib/job_boss/queuer.rb
|
7
|
+
./lib/job_boss/config.rb Sun, 12 Dec 2010 13:50:39 -0500
|
8
|
+
./lib/job_boss/job.rb Sun, 12 Dec 2010 13:45:13 -0500
|
9
|
+
./lib/job_boss/queuer.rb Sun, 12 Dec 2010 13:42:58 -0500
|
10
10
|
./lib/job_boss.rb Fri, 03 Dec 2010 08:55:47 -0500
|
11
|
-
./lib/migrate.rb
|
11
|
+
./lib/migrate.rb Sun, 12 Dec 2010 13:46:41 -0500
|
12
12
|
./MIT-LICENSE Fri, 03 Dec 2010 08:38:44 -0500
|
13
13
|
./Rakefile Sat, 11 Dec 2010 17:05:22 -0500
|
14
14
|
./test/app_root/app/jobs/math_jobs.rb Sun, 28 Nov 2010 10:56:16 -0500
|
@@ -16,6 +16,6 @@ Sat, 11 Dec 2010 17:06:33 -0500
|
|
16
16
|
./test/app_root/app/jobs/string_jobs.rb Sun, 28 Nov 2010 20:04:58 -0500
|
17
17
|
./test/app_root/app/models/penguin.rb Sat, 11 Dec 2010 14:25:33 -0500
|
18
18
|
./test/app_root/config/environment.rb Sat, 11 Dec 2010 16:42:13 -0500
|
19
|
-
./test/test_helper.rb
|
20
|
-
./test/unit/daemon_test.rb Sun,
|
21
|
-
./test/unit/job_test.rb
|
19
|
+
./test/test_helper.rb Sun, 12 Dec 2010 11:27:03 -0500
|
20
|
+
./test/unit/daemon_test.rb Sun, 12 Dec 2010 13:36:55 -0500
|
21
|
+
./test/unit/job_test.rb Sun, 12 Dec 2010 13:47:30 -0500
|
data/doc/index.html
CHANGED
@@ -81,8 +81,6 @@
|
|
81
81
|
|
82
82
|
<li><a href="CreateJobs.html#method-c-down">::down — CreateJobs</a></li>
|
83
83
|
|
84
|
-
<li><a href="JobBoss/Boss.html#method-c-logger">::logger — JobBoss::Boss</a></li>
|
85
|
-
|
86
84
|
<li><a href="JobBoss/Boss.html#method-c-new">::new — JobBoss::Boss</a></li>
|
87
85
|
|
88
86
|
<li><a href="JobBoss/Job.html#method-c-pending_paths">::pending_paths — JobBoss::Job</a></li>
|
@@ -121,6 +119,8 @@
|
|
121
119
|
|
122
120
|
<li><a href="StringJobs.html#method-i-concatenate">#concatenate — StringJobs</a></li>
|
123
121
|
|
122
|
+
<li><a href="JobBoss/Boss.html#method-i-config">#config — JobBoss::Boss</a></li>
|
123
|
+
|
124
124
|
<li><a href="JobBoss/Job.html#method-i-dispatch">#dispatch — JobBoss::Job</a></li>
|
125
125
|
|
126
126
|
<li><a href="SleepJobs.html#method-i-do_not_never_sleep">#do_not_never_sleep — SleepJobs</a></li>
|
@@ -135,6 +135,8 @@
|
|
135
135
|
|
136
136
|
<li><a href="JobBoss/Boss.html#method-i-kill_job">#kill_job — JobBoss::Boss</a></li>
|
137
137
|
|
138
|
+
<li><a href="JobBoss/Boss.html#method-i-logger">#logger — JobBoss::Boss</a></li>
|
139
|
+
|
138
140
|
<li><a href="JobBoss/Job.html#method-i-mark_as_cancelled">#mark_as_cancelled — JobBoss::Job</a></li>
|
139
141
|
|
140
142
|
<li><a href="JobBoss/Job.html#method-i-mark_as_completed">#mark_as_completed — JobBoss::Job</a></li>
|
@@ -149,8 +151,6 @@
|
|
149
151
|
|
150
152
|
<li><a href="JobBoss/Queuer.html#method-i-method_missing">#method_missing — JobBoss::Queuer</a></li>
|
151
153
|
|
152
|
-
<li><a href="JobBoss/Boss.html#method-i-migrate">#migrate — JobBoss::Boss</a></li>
|
153
|
-
|
154
154
|
<li><a href="JobBoss/Config.html#method-i-parse_args">#parse_args — JobBoss::Config</a></li>
|
155
155
|
|
156
156
|
<li><a href="JobBoss/Boss.html#method-i-require_job_classes">#require_job_classes — JobBoss::Boss</a></li>
|
@@ -24,13 +24,15 @@
|
|
24
24
|
<div id="metadata">
|
25
25
|
<dl>
|
26
26
|
<dt class="modified-date">Last Modified</dt>
|
27
|
-
<dd class="modified-date">2010-12-
|
27
|
+
<dd class="modified-date">2010-12-12 13:50:39 -0500</dd>
|
28
28
|
|
29
29
|
|
30
30
|
<dt class="requires">Requires</dt>
|
31
31
|
<dd class="requires">
|
32
32
|
<ul>
|
33
33
|
|
34
|
+
<li>active_support/core_ext/string</li>
|
35
|
+
|
34
36
|
<li>optparse</li>
|
35
37
|
|
36
38
|
</ul>
|
@@ -24,7 +24,7 @@
|
|
24
24
|
<div id="metadata">
|
25
25
|
<dl>
|
26
26
|
<dt class="modified-date">Last Modified</dt>
|
27
|
-
<dd class="modified-date">2010-12-
|
27
|
+
<dd class="modified-date">2010-12-12 13:42:58 -0500</dd>
|
28
28
|
|
29
29
|
|
30
30
|
<dt class="requires">Requires</dt>
|
@@ -35,6 +35,8 @@
|
|
35
35
|
|
36
36
|
<li>job_boss/job</li>
|
37
37
|
|
38
|
+
<li>job_boss/job</li>
|
39
|
+
|
38
40
|
</ul>
|
39
41
|
</dd>
|
40
42
|
|
data/doc/lib/migrate_rb.html
CHANGED
data/job_boss.gemspec
CHANGED
data/lib/job_boss/boss.rb
CHANGED
@@ -2,6 +2,8 @@ require 'active_support'
|
|
2
2
|
|
3
3
|
module JobBoss
|
4
4
|
class Boss
|
5
|
+
extend ActiveSupport::Memoizable
|
6
|
+
|
5
7
|
class << self
|
6
8
|
extend ActiveSupport::Memoizable
|
7
9
|
# Used to set Boss configuration
|
@@ -9,16 +11,18 @@ module JobBoss
|
|
9
11
|
# Boss.config.sleep_interval = 2
|
10
12
|
def config
|
11
13
|
require 'job_boss/config'
|
12
|
-
|
14
|
+
Config.new
|
13
15
|
end
|
16
|
+
memoize :config
|
14
17
|
|
15
18
|
# Used to queue jobs
|
16
19
|
# Usage:
|
17
20
|
# Boss.queue.math.is_prime?(42)
|
18
21
|
def queue
|
19
22
|
require 'job_boss/queuer'
|
20
|
-
|
23
|
+
Queuer.new
|
21
24
|
end
|
25
|
+
memoize :queue
|
22
26
|
|
23
27
|
# Used to queue jobs
|
24
28
|
# Usage:
|
@@ -29,30 +33,34 @@ module JobBoss
|
|
29
33
|
queue.send(controller).send(action, *args)
|
30
34
|
end
|
31
35
|
|
32
|
-
def logger
|
33
|
-
@@config.log_path = resolve_path(@@config.log_path)
|
34
|
-
|
35
|
-
require 'logger'
|
36
|
-
Logger.new(@@config.log_path)
|
37
|
-
end
|
38
|
-
memoize :logger
|
39
|
-
|
40
36
|
# If path starts with '/', leave alone. Otherwise, prepend application_root
|
41
37
|
def resolve_path(path)
|
42
|
-
if path == ?/ || path.match(/^#{
|
38
|
+
if path == ?/ || path.match(/^#{config.application_root}/)
|
43
39
|
path
|
44
40
|
else
|
45
|
-
File.join(
|
41
|
+
File.join(config.application_root, path)
|
46
42
|
end
|
47
43
|
end
|
48
44
|
end
|
49
45
|
|
46
|
+
def config
|
47
|
+
Boss.config
|
48
|
+
end
|
49
|
+
|
50
|
+
def logger
|
51
|
+
config.log_path = Boss.resolve_path(config.log_path)
|
52
|
+
|
53
|
+
require 'logger'
|
54
|
+
Logger.new(config.log_path)
|
55
|
+
end
|
56
|
+
memoize :logger
|
57
|
+
|
50
58
|
def initialize(options = {})
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
59
|
+
config.application_root ||= options[:working_dir]
|
60
|
+
config.sleep_interval ||= options[:sleep_interval]
|
61
|
+
config.employee_limit ||= options[:employee_limit]
|
62
|
+
config.database_yaml_path ||= options[:database_yaml_path]
|
63
|
+
config.jobs_path ||= options[:jobs_path]
|
56
64
|
|
57
65
|
@running_jobs = []
|
58
66
|
end
|
@@ -63,13 +71,10 @@ module JobBoss
|
|
63
71
|
require 'yaml'
|
64
72
|
|
65
73
|
establish_active_record_connection
|
74
|
+
logger.info "Started ActiveRecord connection in '#{config.environment}' environment from database YAML: #{config.database_yaml_path}"
|
66
75
|
|
67
76
|
require_job_classes
|
68
77
|
|
69
|
-
require 'job_boss/job'
|
70
|
-
|
71
|
-
migrate
|
72
|
-
|
73
78
|
Signal.trap("HUP") do
|
74
79
|
stop
|
75
80
|
end
|
@@ -78,11 +83,12 @@ module JobBoss
|
|
78
83
|
stop if Process.pid == BOSS_PID
|
79
84
|
end
|
80
85
|
|
81
|
-
|
86
|
+
logger.info "Job Boss started"
|
87
|
+
logger.info "Employee limit: #{Boss.config.employee_limit}"
|
82
88
|
|
83
89
|
while true
|
84
90
|
unless (children_count = available_employees) > 0 && Job.pending.count > 0
|
85
|
-
sleep(
|
91
|
+
sleep(config.sleep_interval)
|
86
92
|
next
|
87
93
|
end
|
88
94
|
|
@@ -92,7 +98,7 @@ module JobBoss
|
|
92
98
|
job = Job.pending.find_by_path(path)
|
93
99
|
next if job.nil?
|
94
100
|
|
95
|
-
job.dispatch
|
101
|
+
job.dispatch(self)
|
96
102
|
@running_jobs << job
|
97
103
|
|
98
104
|
children_count -= 1
|
@@ -103,11 +109,11 @@ module JobBoss
|
|
103
109
|
end
|
104
110
|
|
105
111
|
def stop
|
106
|
-
|
112
|
+
logger.info "Stopping #{@running_jobs.size} running employees..."
|
107
113
|
|
108
114
|
shutdown_running_jobs
|
109
115
|
|
110
|
-
|
116
|
+
logger.info "Job Boss stopped"
|
111
117
|
end
|
112
118
|
|
113
119
|
private
|
@@ -136,35 +142,34 @@ private
|
|
136
142
|
def available_employees
|
137
143
|
cleanup_running_jobs
|
138
144
|
|
139
|
-
|
145
|
+
config.employee_limit - @running_jobs.size
|
140
146
|
end
|
141
147
|
|
142
148
|
def establish_active_record_connection
|
143
|
-
|
149
|
+
config.database_yaml_path = Boss.resolve_path(config.database_yaml_path)
|
144
150
|
|
145
|
-
raise "Database YAML file missing (#{
|
151
|
+
raise "Database YAML file missing (#{config.database_yaml_path})" unless File.exist?(config.database_yaml_path)
|
146
152
|
|
147
|
-
|
153
|
+
config_data = YAML.load(File.read(config.database_yaml_path))
|
148
154
|
|
149
155
|
ActiveRecord::Base.remove_connection
|
150
|
-
ActiveRecord::Base.establish_connection(
|
151
|
-
end
|
152
|
-
|
153
|
-
def require_job_classes
|
154
|
-
@@config.jobs_path = Boss.resolve_path(@@config.jobs_path)
|
155
|
-
|
156
|
-
raise "Jobs path missing (#{@@config.jobs_path})" unless File.exist?(@@config.jobs_path)
|
157
|
-
|
158
|
-
Dir.glob(File.join(@@config.jobs_path, '*.rb')).each {|job_class| require job_class }
|
159
|
-
end
|
156
|
+
ActiveRecord::Base.establish_connection(config_data[config.environment])
|
160
157
|
|
161
|
-
|
158
|
+
require 'job_boss/job'
|
162
159
|
unless Job.table_exists?
|
163
160
|
require 'migrate'
|
164
161
|
CreateJobs.up
|
165
162
|
end
|
166
163
|
end
|
167
164
|
|
165
|
+
def require_job_classes
|
166
|
+
config.jobs_path = Boss.resolve_path(config.jobs_path)
|
167
|
+
|
168
|
+
raise "Jobs path missing (#{config.jobs_path})" unless File.exist?(config.jobs_path)
|
169
|
+
|
170
|
+
Dir.glob(File.join(config.jobs_path, '*.rb')).each {|job_class| require job_class }
|
171
|
+
end
|
172
|
+
|
168
173
|
def kill_job(job)
|
169
174
|
begin
|
170
175
|
Process.kill("TERM", job.employee_pid.to_i)
|