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.
@@ -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-migrate">#migrate</a></li>
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 10</span>
220
- 10: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config</span>
221
- 11: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/config'</span>
222
- 12: <span class="ruby-identifier">@@config</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">new</span>
223
- 13: <span class="ruby-keyword kw">end</span></pre>
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 50</span>
292
- 50: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span> = {})
293
- 51: <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>]
294
- 52: <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>]
295
- 53: <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>]
296
- 54: <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>]
297
- 55: <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>]
298
- 56:
299
- 57: <span class="ruby-ivar">@running_jobs</span> = []
300
- 58: <span class="ruby-keyword kw">end</span></pre>
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 18</span>
336
- 18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">queue</span>
337
- 19: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/queuer'</span>
338
- 20: <span class="ruby-identifier">@@queuer</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Queuer</span>.<span class="ruby-identifier">new</span>
339
- 21: <span class="ruby-keyword kw">end</span></pre>
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 26</span>
375
- 26: <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>)
376
- 27: <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>)
377
- 28:
378
- 29: <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>)
379
- 30: <span class="ruby-keyword kw">end</span></pre>
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 41</span>
414
- 41: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">resolve_path</span>(<span class="ruby-identifier">path</span>)
415
- 42: <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>)
416
- 43: <span class="ruby-identifier">path</span>
417
- 44: <span class="ruby-keyword kw">else</span>
418
- 45: <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>)
419
- 46: <span class="ruby-keyword kw">end</span>
420
- 47: <span class="ruby-keyword kw">end</span></pre>
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 61</span>
460
- 61: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start</span>
461
- 62: <span class="ruby-identifier">require</span> <span class="ruby-value str">'active_record'</span>
462
- 63: <span class="ruby-identifier">require</span> <span class="ruby-value str">'yaml'</span>
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-constant">Signal</span>.<span class="ruby-identifier">trap</span>(<span class="ruby-value str">&quot;HUP&quot;</span>) <span class="ruby-keyword kw">do</span>
473
- 74: <span class="ruby-identifier">stop</span>
474
- 75: <span class="ruby-keyword kw">end</span>
475
- 76:
476
- 77: <span class="ruby-identifier">at_exit</span> <span class="ruby-keyword kw">do</span>
477
- 78: <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>
478
- 79: <span class="ruby-keyword kw">end</span>
479
- 80:
480
- 81: <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">&quot;Job Boss started&quot;</span>
481
- 82:
482
- 83: <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
483
- 84: <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">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">Job</span>.<span class="ruby-identifier">pending</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
484
- 85: <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">@@config</span>.<span class="ruby-identifier">sleep_interval</span>)
485
- 86: <span class="ruby-keyword kw">next</span>
486
- 87: <span class="ruby-keyword kw">end</span>
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">&quot;Started ActiveRecord connection in '#{config.environment}' environment from database YAML: #{config.database_yaml_path}&quot;</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">&quot;HUP&quot;</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">&quot;Job Boss started&quot;</span>
512
+ 87: <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Employee limit: #{Boss.config.employee_limit}&quot;</span>
487
513
  88:
488
- 89: <span class="ruby-comment cmt"># Go through each pending path so that we don't get stuck just processing</span>
489
- 90: <span class="ruby-comment cmt"># long running jobs which would leave quicker jobs to suffocate</span>
490
- 91: <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>
491
- 92: <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>)
492
- 93: <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>
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">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">Job</span>.<span class="ruby-identifier">pending</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">&gt;</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: <span class="ruby-identifier">job</span>.<span class="ruby-identifier">dispatch</span>
495
- 96: <span class="ruby-ivar">@running_jobs</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">job</span>
496
- 97:
497
- 98: <span class="ruby-identifier">children_count</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
498
- 99: <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">&gt;</span> <span class="ruby-value">0</span>
499
- 100: <span class="ruby-keyword kw">end</span>
500
- 101:
501
- 102: <span class="ruby-keyword kw">end</span>
502
- 103: <span class="ruby-keyword kw">end</span></pre>
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">&lt;&lt;</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">&gt;</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 105</span>
534
- 105: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop</span>
535
- 106: <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Stopping #{@running_jobs.size} running employees...&quot;</span>
536
- 107:
537
- 108: <span class="ruby-identifier">shutdown_running_jobs</span>
538
- 109:
539
- 110: <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">&quot;Job Boss stopped&quot;</span>
540
- 111: <span class="ruby-keyword kw">end</span></pre>
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">&quot;Stopping #{@running_jobs.size} running employees...&quot;</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">&quot;Job Boss stopped&quot;</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 136</span>
580
- 136: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">available_employees</span>
581
- 137: <span class="ruby-identifier">cleanup_running_jobs</span>
582
- 138:
583
- 139: <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>
584
- 140: <span class="ruby-keyword kw">end</span></pre>
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 116</span>
619
- 116: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cleanup_running_jobs</span>
620
- 117: <span class="ruby-constant">Job</span>.<span class="ruby-identifier">uncached</span> <span class="ruby-keyword kw">do</span>
621
- 118: <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>)
622
- 119:
623
- 120: <span class="ruby-identifier">cancelled_jobs</span> = <span class="ruby-ivar">@running_jobs</span>.<span class="ruby-identifier">select</span>(&amp;<span class="ruby-value">:cancelled?</span>)
624
- 121: <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>) }
625
- 122: <span class="ruby-ivar">@running_jobs</span> <span class="ruby-operator">-=</span> <span class="ruby-identifier">cancelled_jobs</span>
626
- 123:
627
- 124: <span class="ruby-comment cmt"># Clean out any jobs whos processes have stopped running for some reason</span>
628
- 125: <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>
629
- 126: <span class="ruby-keyword kw">begin</span>
630
- 127: <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>)
631
- 128: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ESRCH</span>
632
- 129: <span class="ruby-keyword kw">nil</span>
633
- 130: <span class="ruby-keyword kw">end</span>
634
- 131: <span class="ruby-keyword kw">end</span>
635
- 132: <span class="ruby-keyword kw">end</span>
636
- 133: <span class="ruby-keyword kw">end</span></pre>
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>(&amp;<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 142</span>
668
- 142: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">establish_active_record_connection</span>
669
- 143: <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>)
670
- 144:
671
- 145: <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Database YAML file missing (#{@@config.database_yaml_path})&quot;</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>)
672
- 146:
673
- 147: <span class="ruby-identifier">config</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>))
674
- 148:
675
- 149: <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">remove_connection</span>
676
- 150: <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</span>[<span class="ruby-identifier">@@config</span>.<span class="ruby-identifier">environment</span>])
677
- 151: <span class="ruby-keyword kw">end</span></pre>
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">&quot;Database YAML file missing (#{config.database_yaml_path})&quot;</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 168</span>
709
- 168: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">kill_job</span>(<span class="ruby-identifier">job</span>)
710
- 169: <span class="ruby-keyword kw">begin</span>
711
- 170: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value str">&quot;TERM&quot;</span>, <span class="ruby-identifier">job</span>.<span class="ruby-identifier">employee_pid</span>.<span class="ruby-identifier">to_i</span>)
712
- 171: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ESRCH</span>
713
- 172: <span class="ruby-keyword kw">nil</span>
714
- 173: <span class="ruby-keyword kw">end</span>
715
- 174: <span class="ruby-keyword kw">end</span></pre>
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">&quot;TERM&quot;</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 153</span>
784
- 153: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">require_job_classes</span>
785
- 154: <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>)
786
- 155:
787
- 156: <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Jobs path missing (#{@@config.jobs_path})&quot;</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>)
788
- 157:
789
- 158: <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> }
790
- 159: <span class="ruby-keyword kw">end</span></pre>
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">&quot;Jobs path missing (#{config.jobs_path})&quot;</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 176</span>
822
- 176: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown_running_jobs</span>
823
- 177: <span class="ruby-identifier">cleanup_running_jobs</span>
824
- 178:
825
- 179: <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>
826
- 180: <span class="ruby-identifier">kill_job</span>(<span class="ruby-identifier">job</span>)
827
- 181: <span class="ruby-identifier">job</span>.<span class="ruby-identifier">mark_for_redo</span>
828
- 182: <span class="ruby-keyword kw">end</span>
829
- 183: <span class="ruby-keyword kw">end</span></pre>
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>