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/Boss.html
CHANGED
@@ -71,8 +71,6 @@
|
|
71
71
|
|
72
72
|
<li><a href="#method-c-config">::config</a></li>
|
73
73
|
|
74
|
-
<li><a href="#method-c-logger">::logger</a></li>
|
75
|
-
|
76
74
|
<li><a href="#method-c-new">::new</a></li>
|
77
75
|
|
78
76
|
<li><a href="#method-c-queue">::queue</a></li>
|
@@ -85,11 +83,13 @@
|
|
85
83
|
|
86
84
|
<li><a href="#method-i-cleanup_running_jobs">#cleanup_running_jobs</a></li>
|
87
85
|
|
86
|
+
<li><a href="#method-i-config">#config</a></li>
|
87
|
+
|
88
88
|
<li><a href="#method-i-establish_active_record_connection">#establish_active_record_connection</a></li>
|
89
89
|
|
90
90
|
<li><a href="#method-i-kill_job">#kill_job</a></li>
|
91
91
|
|
92
|
-
<li><a href="#method-i-
|
92
|
+
<li><a href="#method-i-logger">#logger</a></li>
|
93
93
|
|
94
94
|
<li><a href="#method-i-require_job_classes">#require_job_classes</a></li>
|
95
95
|
|
@@ -216,48 +216,11 @@ Used to set <a href="Boss.html">Boss</a> configuration Usage:
|
|
216
216
|
<div class="method-source-code"
|
217
217
|
id="config-source">
|
218
218
|
<pre>
|
219
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
</div>
|
225
|
-
|
226
|
-
</div>
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
</div>
|
232
|
-
|
233
|
-
|
234
|
-
<div id="logger-method" class="method-detail ">
|
235
|
-
<a name="method-c-logger"></a>
|
236
|
-
|
237
|
-
<div class="method-heading">
|
238
|
-
|
239
|
-
<span class="method-name">logger</span><span
|
240
|
-
class="method-args">()</span>
|
241
|
-
<span class="method-click-advice">click to toggle source</span>
|
242
|
-
|
243
|
-
</div>
|
244
|
-
|
245
|
-
<div class="method-description">
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
<div class="method-source-code"
|
252
|
-
id="logger-source">
|
253
|
-
<pre>
|
254
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 32</span>
|
255
|
-
32: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">logger</span>
|
256
|
-
33: <span class="ruby-identifier">@@config</span>.<span class="ruby-identifier">log_path</span> = <span class="ruby-identifier">resolve_path</span>(<span class="ruby-identifier">@@config</span>.<span class="ruby-identifier">log_path</span>)
|
257
|
-
34:
|
258
|
-
35: <span class="ruby-identifier">require</span> <span class="ruby-value str">'logger'</span>
|
259
|
-
36: <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">@@config</span>.<span class="ruby-identifier">log_path</span>)
|
260
|
-
37: <span class="ruby-keyword kw">end</span></pre>
|
219
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 12</span>
|
220
|
+
12: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config</span>
|
221
|
+
13: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/config'</span>
|
222
|
+
14: <span class="ruby-constant">Config</span>.<span class="ruby-identifier">new</span>
|
223
|
+
15: <span class="ruby-keyword kw">end</span></pre>
|
261
224
|
</div>
|
262
225
|
|
263
226
|
</div>
|
@@ -288,16 +251,16 @@ Used to set <a href="Boss.html">Boss</a> configuration Usage:
|
|
288
251
|
<div class="method-source-code"
|
289
252
|
id="new-source">
|
290
253
|
<pre>
|
291
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
254
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 58</span>
|
255
|
+
58: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span> = {})
|
256
|
+
59: <span class="ruby-identifier">config</span>.<span class="ruby-identifier">application_root</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:working_dir</span>]
|
257
|
+
60: <span class="ruby-identifier">config</span>.<span class="ruby-identifier">sleep_interval</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:sleep_interval</span>]
|
258
|
+
61: <span class="ruby-identifier">config</span>.<span class="ruby-identifier">employee_limit</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:employee_limit</span>]
|
259
|
+
62: <span class="ruby-identifier">config</span>.<span class="ruby-identifier">database_yaml_path</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:database_yaml_path</span>]
|
260
|
+
63: <span class="ruby-identifier">config</span>.<span class="ruby-identifier">jobs_path</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:jobs_path</span>]
|
261
|
+
64:
|
262
|
+
65: <span class="ruby-ivar">@running_jobs</span> = []
|
263
|
+
66: <span class="ruby-keyword kw">end</span></pre>
|
301
264
|
</div>
|
302
265
|
|
303
266
|
</div>
|
@@ -332,11 +295,11 @@ Used to queue jobs Usage:
|
|
332
295
|
<div class="method-source-code"
|
333
296
|
id="queue-source">
|
334
297
|
<pre>
|
335
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
298
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 21</span>
|
299
|
+
21: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">queue</span>
|
300
|
+
22: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/queuer'</span>
|
301
|
+
23: <span class="ruby-constant">Queuer</span>.<span class="ruby-identifier">new</span>
|
302
|
+
24: <span class="ruby-keyword kw">end</span></pre>
|
340
303
|
</div>
|
341
304
|
|
342
305
|
</div>
|
@@ -371,12 +334,12 @@ Used to queue jobs Usage:
|
|
371
334
|
<div class="method-source-code"
|
372
335
|
id="queue-path-source">
|
373
336
|
<pre>
|
374
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
337
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 30</span>
|
338
|
+
30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">queue_path</span>(<span class="ruby-identifier">path</span>, *<span class="ruby-identifier">args</span>)
|
339
|
+
31: <span class="ruby-identifier">controller</span>, <span class="ruby-identifier">action</span> = <span class="ruby-identifier">path</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'#'</span>)
|
340
|
+
32:
|
341
|
+
33: <span class="ruby-identifier">queue</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">controller</span>).<span class="ruby-identifier">send</span>(<span class="ruby-identifier">action</span>, *<span class="ruby-identifier">args</span>)
|
342
|
+
34: <span class="ruby-keyword kw">end</span></pre>
|
380
343
|
</div>
|
381
344
|
|
382
345
|
</div>
|
@@ -410,14 +373,14 @@ application_root
|
|
410
373
|
<div class="method-source-code"
|
411
374
|
id="resolve-path-source">
|
412
375
|
<pre>
|
413
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
376
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 37</span>
|
377
|
+
37: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">resolve_path</span>(<span class="ruby-identifier">path</span>)
|
378
|
+
38: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">path</span> <span class="ruby-operator">==</span> <span class="ruby-value">//</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">path</span>.<span class="ruby-identifier">match</span>(<span class="ruby-node">/^#{config.application_root}/</span>)
|
379
|
+
39: <span class="ruby-identifier">path</span>
|
380
|
+
40: <span class="ruby-keyword kw">else</span>
|
381
|
+
41: <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">application_root</span>, <span class="ruby-identifier">path</span>)
|
382
|
+
42: <span class="ruby-keyword kw">end</span>
|
383
|
+
43: <span class="ruby-keyword kw">end</span></pre>
|
421
384
|
</div>
|
422
385
|
|
423
386
|
</div>
|
@@ -434,6 +397,77 @@ application_root
|
|
434
397
|
<h3 class="section-header">Public Instance Methods</h3>
|
435
398
|
|
436
399
|
|
400
|
+
<div id="config-method" class="method-detail ">
|
401
|
+
<a name="method-i-config"></a>
|
402
|
+
|
403
|
+
<div class="method-heading">
|
404
|
+
|
405
|
+
<span class="method-name">config</span><span
|
406
|
+
class="method-args">()</span>
|
407
|
+
<span class="method-click-advice">click to toggle source</span>
|
408
|
+
|
409
|
+
</div>
|
410
|
+
|
411
|
+
<div class="method-description">
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
<div class="method-source-code"
|
418
|
+
id="config-source">
|
419
|
+
<pre>
|
420
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 46</span>
|
421
|
+
46: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config</span>
|
422
|
+
47: <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">config</span>
|
423
|
+
48: <span class="ruby-keyword kw">end</span></pre>
|
424
|
+
</div>
|
425
|
+
|
426
|
+
</div>
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
</div>
|
432
|
+
|
433
|
+
|
434
|
+
<div id="logger-method" class="method-detail ">
|
435
|
+
<a name="method-i-logger"></a>
|
436
|
+
|
437
|
+
<div class="method-heading">
|
438
|
+
|
439
|
+
<span class="method-name">logger</span><span
|
440
|
+
class="method-args">()</span>
|
441
|
+
<span class="method-click-advice">click to toggle source</span>
|
442
|
+
|
443
|
+
</div>
|
444
|
+
|
445
|
+
<div class="method-description">
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
<div class="method-source-code"
|
452
|
+
id="logger-source">
|
453
|
+
<pre>
|
454
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 50</span>
|
455
|
+
50: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">logger</span>
|
456
|
+
51: <span class="ruby-identifier">config</span>.<span class="ruby-identifier">log_path</span> = <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">resolve_path</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">log_path</span>)
|
457
|
+
52:
|
458
|
+
53: <span class="ruby-identifier">require</span> <span class="ruby-value str">'logger'</span>
|
459
|
+
54: <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">log_path</span>)
|
460
|
+
55: <span class="ruby-keyword kw">end</span></pre>
|
461
|
+
</div>
|
462
|
+
|
463
|
+
</div>
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
|
468
|
+
</div>
|
469
|
+
|
470
|
+
|
437
471
|
<div id="start-method" class="method-detail ">
|
438
472
|
<a name="method-i-start"></a>
|
439
473
|
|
@@ -456,50 +490,48 @@ Start the boss
|
|
456
490
|
<div class="method-source-code"
|
457
491
|
id="start-source">
|
458
492
|
<pre>
|
459
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
64:
|
464
|
-
65: <span class="ruby-identifier">establish_active_record_connection</span>
|
465
|
-
66:
|
466
|
-
67: <span class="ruby-identifier">require_job_classes</span>
|
467
|
-
68:
|
468
|
-
69: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/job'</span>
|
469
|
-
70:
|
470
|
-
71: <span class="ruby-identifier">migrate</span>
|
493
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 69</span>
|
494
|
+
69: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start</span>
|
495
|
+
70: <span class="ruby-identifier">require</span> <span class="ruby-value str">'active_record'</span>
|
496
|
+
71: <span class="ruby-identifier">require</span> <span class="ruby-value str">'yaml'</span>
|
471
497
|
72:
|
472
|
-
73: <span class="ruby-
|
473
|
-
74:
|
474
|
-
75:
|
475
|
-
76:
|
476
|
-
77:
|
477
|
-
78:
|
478
|
-
79:
|
479
|
-
80:
|
480
|
-
81:
|
481
|
-
82:
|
482
|
-
83:
|
483
|
-
84:
|
484
|
-
85:
|
485
|
-
86:
|
486
|
-
87:
|
498
|
+
73: <span class="ruby-identifier">establish_active_record_connection</span>
|
499
|
+
74: <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">"Started ActiveRecord connection in '#{config.environment}' environment from database YAML: #{config.database_yaml_path}"</span>
|
500
|
+
75:
|
501
|
+
76: <span class="ruby-identifier">require_job_classes</span>
|
502
|
+
77:
|
503
|
+
78: <span class="ruby-constant">Signal</span>.<span class="ruby-identifier">trap</span>(<span class="ruby-value str">"HUP"</span>) <span class="ruby-keyword kw">do</span>
|
504
|
+
79: <span class="ruby-identifier">stop</span>
|
505
|
+
80: <span class="ruby-keyword kw">end</span>
|
506
|
+
81:
|
507
|
+
82: <span class="ruby-identifier">at_exit</span> <span class="ruby-keyword kw">do</span>
|
508
|
+
83: <span class="ruby-identifier">stop</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Process</span>.<span class="ruby-identifier">pid</span> <span class="ruby-operator">==</span> <span class="ruby-constant">BOSS_PID</span>
|
509
|
+
84: <span class="ruby-keyword kw">end</span>
|
510
|
+
85:
|
511
|
+
86: <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">"Job Boss started"</span>
|
512
|
+
87: <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">"Employee limit: #{Boss.config.employee_limit}"</span>
|
487
513
|
88:
|
488
|
-
89:
|
489
|
-
90: <span class="ruby-
|
490
|
-
91:
|
491
|
-
92: <span class="ruby-
|
492
|
-
93:
|
514
|
+
89: <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
|
515
|
+
90: <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">children_count</span> = <span class="ruby-identifier">available_employees</span>) <span class="ruby-operator">></span> <span class="ruby-value">0</span> <span class="ruby-operator">&&</span> <span class="ruby-constant">Job</span>.<span class="ruby-identifier">pending</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
516
|
+
91: <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">sleep_interval</span>)
|
517
|
+
92: <span class="ruby-keyword kw">next</span>
|
518
|
+
93: <span class="ruby-keyword kw">end</span>
|
493
519
|
94:
|
494
|
-
95:
|
495
|
-
96:
|
496
|
-
97:
|
497
|
-
98: <span class="ruby-identifier">
|
498
|
-
99: <span class="ruby-keyword kw">
|
499
|
-
100:
|
500
|
-
101:
|
501
|
-
102:
|
502
|
-
103:
|
520
|
+
95: <span class="ruby-comment cmt"># Go through each pending path so that we don't get stuck just processing</span>
|
521
|
+
96: <span class="ruby-comment cmt"># long running jobs which would leave quicker jobs to suffocate</span>
|
522
|
+
97: <span class="ruby-constant">Job</span>.<span class="ruby-identifier">pending_paths</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
|
523
|
+
98: <span class="ruby-identifier">job</span> = <span class="ruby-constant">Job</span>.<span class="ruby-identifier">pending</span>.<span class="ruby-identifier">find_by_path</span>(<span class="ruby-identifier">path</span>)
|
524
|
+
99: <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">job</span>.<span class="ruby-identifier">nil?</span>
|
525
|
+
100:
|
526
|
+
101: <span class="ruby-identifier">job</span>.<span class="ruby-identifier">dispatch</span>(<span class="ruby-keyword kw">self</span>)
|
527
|
+
102: <span class="ruby-ivar">@running_jobs</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">job</span>
|
528
|
+
103:
|
529
|
+
104: <span class="ruby-identifier">children_count</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
530
|
+
105: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">children_count</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
531
|
+
106: <span class="ruby-keyword kw">end</span>
|
532
|
+
107:
|
533
|
+
108: <span class="ruby-keyword kw">end</span>
|
534
|
+
109: <span class="ruby-keyword kw">end</span></pre>
|
503
535
|
</div>
|
504
536
|
|
505
537
|
</div>
|
@@ -530,14 +562,14 @@ Start the boss
|
|
530
562
|
<div class="method-source-code"
|
531
563
|
id="stop-source">
|
532
564
|
<pre>
|
533
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
565
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 111</span>
|
566
|
+
111: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop</span>
|
567
|
+
112: <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">"Stopping #{@running_jobs.size} running employees..."</span>
|
568
|
+
113:
|
569
|
+
114: <span class="ruby-identifier">shutdown_running_jobs</span>
|
570
|
+
115:
|
571
|
+
116: <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">"Job Boss stopped"</span>
|
572
|
+
117: <span class="ruby-keyword kw">end</span></pre>
|
541
573
|
</div>
|
542
574
|
|
543
575
|
</div>
|
@@ -576,12 +608,12 @@ Total number of employees which can be run
|
|
576
608
|
<div class="method-source-code"
|
577
609
|
id="available-employees-source">
|
578
610
|
<pre>
|
579
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
611
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 142</span>
|
612
|
+
142: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">available_employees</span>
|
613
|
+
143: <span class="ruby-identifier">cleanup_running_jobs</span>
|
614
|
+
144:
|
615
|
+
145: <span class="ruby-identifier">config</span>.<span class="ruby-identifier">employee_limit</span> <span class="ruby-operator">-</span> <span class="ruby-ivar">@running_jobs</span>.<span class="ruby-identifier">size</span>
|
616
|
+
146: <span class="ruby-keyword kw">end</span></pre>
|
585
617
|
</div>
|
586
618
|
|
587
619
|
</div>
|
@@ -615,25 +647,25 @@ which have been cancelled, or which went MIA
|
|
615
647
|
<div class="method-source-code"
|
616
648
|
id="cleanup-running-jobs-source">
|
617
649
|
<pre>
|
618
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
650
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 122</span>
|
651
|
+
122: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cleanup_running_jobs</span>
|
652
|
+
123: <span class="ruby-constant">Job</span>.<span class="ruby-identifier">uncached</span> <span class="ruby-keyword kw">do</span>
|
653
|
+
124: <span class="ruby-ivar">@running_jobs</span> = <span class="ruby-constant">Job</span>.<span class="ruby-identifier">running</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value str">'id in (?)'</span>, <span class="ruby-ivar">@running_jobs</span>)
|
654
|
+
125:
|
655
|
+
126: <span class="ruby-identifier">cancelled_jobs</span> = <span class="ruby-ivar">@running_jobs</span>.<span class="ruby-identifier">select</span>(&<span class="ruby-value">:cancelled?</span>)
|
656
|
+
127: <span class="ruby-identifier">cancelled_jobs</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">job</span><span class="ruby-operator">|</span> <span class="ruby-identifier">kill_job</span>(<span class="ruby-identifier">job</span>) }
|
657
|
+
128: <span class="ruby-ivar">@running_jobs</span> <span class="ruby-operator">-=</span> <span class="ruby-identifier">cancelled_jobs</span>
|
658
|
+
129:
|
659
|
+
130: <span class="ruby-comment cmt"># Clean out any jobs whos processes have stopped running for some reason</span>
|
660
|
+
131: <span class="ruby-ivar">@running_jobs</span> = <span class="ruby-ivar">@running_jobs</span>.<span class="ruby-identifier">select</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">job</span><span class="ruby-operator">|</span>
|
661
|
+
132: <span class="ruby-keyword kw">begin</span>
|
662
|
+
133: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">job</span>.<span class="ruby-identifier">employee_pid</span>.<span class="ruby-identifier">to_i</span>)
|
663
|
+
134: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ESRCH</span>
|
664
|
+
135: <span class="ruby-keyword kw">nil</span>
|
665
|
+
136: <span class="ruby-keyword kw">end</span>
|
666
|
+
137: <span class="ruby-keyword kw">end</span>
|
667
|
+
138: <span class="ruby-keyword kw">end</span>
|
668
|
+
139: <span class="ruby-keyword kw">end</span></pre>
|
637
669
|
</div>
|
638
670
|
|
639
671
|
</div>
|
@@ -664,17 +696,23 @@ which have been cancelled, or which went MIA
|
|
664
696
|
<div class="method-source-code"
|
665
697
|
id="establish-active-record-connection-source">
|
666
698
|
<pre>
|
667
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
699
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 148</span>
|
700
|
+
148: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">establish_active_record_connection</span>
|
701
|
+
149: <span class="ruby-identifier">config</span>.<span class="ruby-identifier">database_yaml_path</span> = <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">resolve_path</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">database_yaml_path</span>)
|
702
|
+
150:
|
703
|
+
151: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Database YAML file missing (#{config.database_yaml_path})"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">database_yaml_path</span>)
|
704
|
+
152:
|
705
|
+
153: <span class="ruby-identifier">config_data</span> = <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">database_yaml_path</span>))
|
706
|
+
154:
|
707
|
+
155: <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">remove_connection</span>
|
708
|
+
156: <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">establish_connection</span>(<span class="ruby-identifier">config_data</span>[<span class="ruby-identifier">config</span>.<span class="ruby-identifier">environment</span>])
|
709
|
+
157:
|
710
|
+
158: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/job'</span>
|
711
|
+
159: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Job</span>.<span class="ruby-identifier">table_exists?</span>
|
712
|
+
160: <span class="ruby-identifier">require</span> <span class="ruby-value str">'migrate'</span>
|
713
|
+
161: <span class="ruby-constant">CreateJobs</span>.<span class="ruby-identifier">up</span>
|
714
|
+
162: <span class="ruby-keyword kw">end</span>
|
715
|
+
163: <span class="ruby-keyword kw">end</span></pre>
|
678
716
|
</div>
|
679
717
|
|
680
718
|
</div>
|
@@ -705,51 +743,14 @@ which have been cancelled, or which went MIA
|
|
705
743
|
<div class="method-source-code"
|
706
744
|
id="kill-job-source">
|
707
745
|
<pre>
|
708
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
</div>
|
717
|
-
|
718
|
-
</div>
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
</div>
|
724
|
-
|
725
|
-
|
726
|
-
<div id="migrate-method" class="method-detail ">
|
727
|
-
<a name="method-i-migrate"></a>
|
728
|
-
|
729
|
-
<div class="method-heading">
|
730
|
-
|
731
|
-
<span class="method-name">migrate</span><span
|
732
|
-
class="method-args">()</span>
|
733
|
-
<span class="method-click-advice">click to toggle source</span>
|
734
|
-
|
735
|
-
</div>
|
736
|
-
|
737
|
-
<div class="method-description">
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
<div class="method-source-code"
|
744
|
-
id="migrate-source">
|
745
|
-
<pre>
|
746
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 161</span>
|
747
|
-
161: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">migrate</span>
|
748
|
-
162: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Job</span>.<span class="ruby-identifier">table_exists?</span>
|
749
|
-
163: <span class="ruby-identifier">require</span> <span class="ruby-value str">'migrate'</span>
|
750
|
-
164: <span class="ruby-constant">CreateJobs</span>.<span class="ruby-identifier">up</span>
|
751
|
-
165: <span class="ruby-keyword kw">end</span>
|
752
|
-
166: <span class="ruby-keyword kw">end</span></pre>
|
746
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 173</span>
|
747
|
+
173: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">kill_job</span>(<span class="ruby-identifier">job</span>)
|
748
|
+
174: <span class="ruby-keyword kw">begin</span>
|
749
|
+
175: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value str">"TERM"</span>, <span class="ruby-identifier">job</span>.<span class="ruby-identifier">employee_pid</span>.<span class="ruby-identifier">to_i</span>)
|
750
|
+
176: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ESRCH</span>
|
751
|
+
177: <span class="ruby-keyword kw">nil</span>
|
752
|
+
178: <span class="ruby-keyword kw">end</span>
|
753
|
+
179: <span class="ruby-keyword kw">end</span></pre>
|
753
754
|
</div>
|
754
755
|
|
755
756
|
</div>
|
@@ -780,14 +781,14 @@ which have been cancelled, or which went MIA
|
|
780
781
|
<div class="method-source-code"
|
781
782
|
id="require-job-classes-source">
|
782
783
|
<pre>
|
783
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
784
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 165</span>
|
785
|
+
165: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">require_job_classes</span>
|
786
|
+
166: <span class="ruby-identifier">config</span>.<span class="ruby-identifier">jobs_path</span> = <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">resolve_path</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">jobs_path</span>)
|
787
|
+
167:
|
788
|
+
168: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Jobs path missing (#{config.jobs_path})"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">jobs_path</span>)
|
789
|
+
169:
|
790
|
+
170: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">jobs_path</span>, <span class="ruby-value str">'*.rb'</span>)).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">job_class</span><span class="ruby-operator">|</span> <span class="ruby-identifier">require</span> <span class="ruby-identifier">job_class</span> }
|
791
|
+
171: <span class="ruby-keyword kw">end</span></pre>
|
791
792
|
</div>
|
792
793
|
|
793
794
|
</div>
|
@@ -818,15 +819,15 @@ which have been cancelled, or which went MIA
|
|
818
819
|
<div class="method-source-code"
|
819
820
|
id="shutdown-running-jobs-source">
|
820
821
|
<pre>
|
821
|
-
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
822
|
+
<span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 181</span>
|
823
|
+
181: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown_running_jobs</span>
|
824
|
+
182: <span class="ruby-identifier">cleanup_running_jobs</span>
|
825
|
+
183:
|
826
|
+
184: <span class="ruby-ivar">@running_jobs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">job</span><span class="ruby-operator">|</span>
|
827
|
+
185: <span class="ruby-identifier">kill_job</span>(<span class="ruby-identifier">job</span>)
|
828
|
+
186: <span class="ruby-identifier">job</span>.<span class="ruby-identifier">mark_for_redo</span>
|
829
|
+
187: <span class="ruby-keyword kw">end</span>
|
830
|
+
188: <span class="ruby-keyword kw">end</span></pre>
|
830
831
|
</div>
|
831
832
|
|
832
833
|
</div>
|