job_boss 0.5.0 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +39 -7
- data/bin/job_boss +4 -2
- data/doc/ActiveSupport/TestCase.html +106 -87
- data/doc/ActiveSupport.html +6 -0
- data/doc/CreateJobs.html +17 -5
- data/doc/DaemonTest.html +6 -0
- data/doc/Gemfile.html +128 -0
- data/doc/JobBoss/Boss.html +193 -144
- data/doc/JobBoss/Config.html +8 -2
- data/doc/JobBoss/Job.html +224 -166
- data/doc/JobBoss/Queuer.html +25 -11
- data/doc/JobBoss.html +9 -0
- data/doc/MIT-LICENSE.html +137 -0
- data/doc/MathJobs.html +6 -0
- data/doc/Penguin.html +223 -0
- data/doc/Rakefile.html +6 -0
- data/doc/SleepJobs.html +6 -0
- data/doc/StringJobs.html +7 -1
- data/doc/bin/job_boss.html +3 -1
- data/doc/created.rid +17 -11
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +12 -0
- data/doc/init_rb.html +54 -0
- data/doc/js/darkfish.js +116 -0
- data/doc/js/jquery.js +32 -0
- data/doc/js/quicksearch.js +114 -0
- data/doc/js/thickbox-compressed.js +10 -0
- data/doc/lib/job_boss/boss_rb.html +1 -1
- data/doc/lib/job_boss/config_rb.html +1 -1
- data/doc/lib/job_boss/job_rb.html +1 -1
- data/doc/lib/job_boss/queuer_rb.html +1 -1
- data/doc/lib/job_boss_rb.html +56 -0
- data/doc/lib/migrate_rb.html +1 -1
- data/doc/test/app_root/app/jobs/string_jobs_rb.html +1 -1
- data/doc/test/app_root/app/models/penguin_rb.html +52 -0
- data/doc/test/app_root/config/environment_rb.html +56 -0
- data/doc/test/test_helper_rb.html +3 -1
- data/doc/test/unit/job_test_rb.html +2 -4
- data/job_boss.gemspec +1 -1
- data/lib/job_boss/config.rb +2 -2
- data/lib/job_boss/job.rb +22 -2
- data/lib/job_boss/queuer.rb +10 -2
- data/lib/migrate.rb +6 -0
- data/test/app_root/app/models/penguin.rb +9 -0
- data/test/app_root/config/database.yml +3 -3
- data/test/app_root/config/environment.rb +3 -0
- data/test/test_helper.rb +6 -4
- data/test/unit/job_test.rb +33 -17
- metadata +38 -9
data/doc/JobBoss/Job.html
CHANGED
@@ -71,6 +71,8 @@
|
|
71
71
|
|
72
72
|
<li><a href="#method-c-call_path">::call_path</a></li>
|
73
73
|
|
74
|
+
<li><a href="#method-c-delete_jobs_before">::delete_jobs_before</a></li>
|
75
|
+
|
74
76
|
<li><a href="#method-c-pending_paths">::pending_paths</a></li>
|
75
77
|
|
76
78
|
<li><a href="#method-c-result_hash">::result_hash</a></li>
|
@@ -124,6 +126,10 @@
|
|
124
126
|
<h3 class="section-header">Files</h3>
|
125
127
|
<ul>
|
126
128
|
|
129
|
+
<li class="file"><a href="../Gemfile.html">Gemfile</a></li>
|
130
|
+
|
131
|
+
<li class="file"><a href="../MIT-LICENSE.html">MIT-LICENSE</a></li>
|
132
|
+
|
127
133
|
<li class="file"><a href="../Rakefile.html">Rakefile</a></li>
|
128
134
|
|
129
135
|
</ul>
|
@@ -165,6 +171,8 @@
|
|
165
171
|
|
166
172
|
<li><a href="../MathJobs.html">MathJobs</a></li>
|
167
173
|
|
174
|
+
<li><a href="../Penguin.html">Penguin</a></li>
|
175
|
+
|
168
176
|
<li><a href="../SleepJobs.html">SleepJobs</a></li>
|
169
177
|
|
170
178
|
<li><a href="../StringJobs.html">StringJobs</a></li>
|
@@ -196,6 +204,43 @@
|
|
196
204
|
<h3 class="section-header">Public Class Methods</h3>
|
197
205
|
|
198
206
|
|
207
|
+
<div id="delete-jobs-before-method" class="method-detail ">
|
208
|
+
<a name="method-c-delete_jobs_before"></a>
|
209
|
+
|
210
|
+
<div class="method-heading">
|
211
|
+
|
212
|
+
<span class="method-name">delete_jobs_before</span><span
|
213
|
+
class="method-args">(time)</span>
|
214
|
+
<span class="method-click-advice">click to toggle source</span>
|
215
|
+
|
216
|
+
</div>
|
217
|
+
|
218
|
+
<div class="method-description">
|
219
|
+
|
220
|
+
<p>
|
221
|
+
Given a time object Delete all jobs which were completed earlier than that
|
222
|
+
time
|
223
|
+
</p>
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
<div class="method-source-code"
|
228
|
+
id="delete-jobs-before-source">
|
229
|
+
<pre>
|
230
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 164</span>
|
231
|
+
164: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_jobs_before</span>(<span class="ruby-identifier">time</span>)
|
232
|
+
165: <span class="ruby-identifier">completed</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value str">'completed_at < ?'</span>, <span class="ruby-identifier">time</span>).<span class="ruby-identifier">delete_all</span>
|
233
|
+
166: <span class="ruby-keyword kw">end</span></pre>
|
234
|
+
</div>
|
235
|
+
|
236
|
+
</div>
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
</div>
|
242
|
+
|
243
|
+
|
199
244
|
<div id="result-hash-method" class="method-detail ">
|
200
245
|
<a name="method-c-result_hash"></a>
|
201
246
|
|
@@ -209,26 +254,29 @@
|
|
209
254
|
|
210
255
|
<div class="method-description">
|
211
256
|
|
212
|
-
|
257
|
+
<p>
|
258
|
+
Given a job or an array of jobs Returns a hash where the keys are the job
|
259
|
+
method arguments and the values are the results of the job processing
|
260
|
+
</p>
|
213
261
|
|
214
262
|
|
215
263
|
|
216
264
|
<div class="method-source-code"
|
217
265
|
id="result-hash-source">
|
218
266
|
<pre>
|
219
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
267
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 149</span>
|
268
|
+
149: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">result_hash</span>(<span class="ruby-identifier">jobs</span>)
|
269
|
+
150: <span class="ruby-identifier">jobs</span> = [<span class="ruby-identifier">jobs</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Job</span>)
|
270
|
+
151:
|
271
|
+
152: <span class="ruby-comment cmt"># the #result method automatically reloads the result here if needed but this will</span>
|
272
|
+
153: <span class="ruby-comment cmt"># do it in one SQL call</span>
|
273
|
+
154: <span class="ruby-identifier">jobs</span> = <span class="ruby-constant">Job</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">collect</span>(&<span class="ruby-value">:id</span>))
|
274
|
+
155:
|
275
|
+
156: <span class="ruby-identifier">require</span> <span class="ruby-value str">'yaml'</span>
|
276
|
+
157: <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hash</span>, <span class="ruby-identifier">job</span><span class="ruby-operator">|</span>
|
277
|
+
158: <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">job</span>.<span class="ruby-identifier">args</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">job</span>.<span class="ruby-identifier">result</span>)
|
278
|
+
159: <span class="ruby-keyword kw">end</span>
|
279
|
+
160: <span class="ruby-keyword kw">end</span></pre>
|
232
280
|
</div>
|
233
281
|
|
234
282
|
</div>
|
@@ -252,24 +300,29 @@
|
|
252
300
|
|
253
301
|
<div class="method-description">
|
254
302
|
|
255
|
-
|
303
|
+
<p>
|
304
|
+
Given a job or an array of jobs Will cause the process to sleep until all
|
305
|
+
specified jobs have completed sleep_interval specifies polling period
|
306
|
+
</p>
|
256
307
|
|
257
308
|
|
258
309
|
|
259
310
|
<div class="method-source-code"
|
260
311
|
id="wait-for-jobs-source">
|
261
312
|
<pre>
|
262
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
313
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 133</span>
|
314
|
+
133: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait_for_jobs</span>(<span class="ruby-identifier">jobs</span>, <span class="ruby-identifier">sleep_interval</span> = <span class="ruby-value">0.5</span>)
|
315
|
+
134: <span class="ruby-identifier">jobs</span> = [<span class="ruby-identifier">jobs</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Job</span>)
|
316
|
+
135:
|
317
|
+
136: <span class="ruby-identifier">ids</span> = <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">collect</span>(&<span class="ruby-value">:id</span>)
|
318
|
+
137: <span class="ruby-constant">Job</span>.<span class="ruby-identifier">uncached</span> <span class="ruby-keyword kw">do</span>
|
319
|
+
138: <span class="ruby-keyword kw">until</span> <span class="ruby-constant">Job</span>.<span class="ruby-identifier">completed</span>.<span class="ruby-identifier">find_all_by_id</span>(<span class="ruby-identifier">ids</span>).<span class="ruby-identifier">count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">size</span>
|
320
|
+
139: <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">sleep_interval</span>)
|
321
|
+
140: <span class="ruby-keyword kw">end</span>
|
322
|
+
141: <span class="ruby-keyword kw">end</span>
|
323
|
+
142:
|
324
|
+
143: <span class="ruby-keyword kw">true</span>
|
325
|
+
144: <span class="ruby-keyword kw">end</span></pre>
|
273
326
|
</div>
|
274
327
|
|
275
328
|
</div>
|
@@ -306,23 +359,27 @@
|
|
306
359
|
<div class="method-source-code"
|
307
360
|
id="call-path-source">
|
308
361
|
<pre>
|
309
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
362
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 196</span>
|
363
|
+
196: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call_path</span>(<span class="ruby-identifier">path</span>, *<span class="ruby-identifier">args</span>)
|
364
|
+
197: <span class="ruby-identifier">require</span> <span class="ruby-value str">'active_support'</span>
|
365
|
+
198:
|
366
|
+
199: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Invalid path (must have #)"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">path</span>.<span class="ruby-identifier">match</span>(<span class="ruby-node">/.#./</span>)
|
367
|
+
200: <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>)
|
368
|
+
201:
|
369
|
+
202: <span class="ruby-identifier">controller_object</span> = <span class="ruby-keyword kw">begin</span>
|
370
|
+
203: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-node">"#{controller.classify}Jobs"</span>).<span class="ruby-identifier">new</span>
|
371
|
+
204: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
|
372
|
+
205: <span class="ruby-keyword kw">begin</span>
|
373
|
+
206: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-node">"#{controller.classify}"</span>)
|
374
|
+
207: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
|
375
|
+
208: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Invalid controller: #{controller}"</span>
|
376
|
+
209: <span class="ruby-keyword kw">end</span>
|
377
|
+
210: <span class="ruby-keyword kw">end</span>
|
378
|
+
211:
|
379
|
+
212: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Invalid path action: #{action}"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">controller_object</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">action</span>)
|
380
|
+
213:
|
381
|
+
214: <span class="ruby-identifier">controller_object</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">action</span>, *<span class="ruby-identifier">args</span>)
|
382
|
+
215: <span class="ruby-keyword kw">end</span></pre>
|
326
383
|
</div>
|
327
384
|
|
328
385
|
</div>
|
@@ -353,10 +410,10 @@
|
|
353
410
|
<div class="method-source-code"
|
354
411
|
id="pending-paths-source">
|
355
412
|
<pre>
|
356
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
357
|
-
|
358
|
-
|
359
|
-
|
413
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 217</span>
|
414
|
+
217: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pending_paths</span>
|
415
|
+
218: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">pending</span>.<span class="ruby-identifier">except</span>(<span class="ruby-value">:order</span>).<span class="ruby-identifier">select</span>(<span class="ruby-value str">'DISTINCT path'</span>).<span class="ruby-identifier">collect</span>(&<span class="ruby-value">:path</span>)
|
416
|
+
219: <span class="ruby-keyword kw">end</span></pre>
|
360
417
|
</div>
|
361
418
|
|
362
419
|
</div>
|
@@ -395,14 +452,14 @@ Has the job been assigned to an employee?
|
|
395
452
|
<div class="method-source-code"
|
396
453
|
id="assigned--source">
|
397
454
|
<pre>
|
398
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
455
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 98</span>
|
456
|
+
98: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assigned?</span>
|
457
|
+
99: <span class="ruby-comment cmt"># If the #assigned? method is being called for but the job hasn't been completed, reload</span>
|
458
|
+
100: <span class="ruby-comment cmt"># to check to see if it has been assigned</span>
|
459
|
+
101: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">completed?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">employee_pid</span>.<span class="ruby-identifier">nil?</span>
|
460
|
+
102:
|
461
|
+
103: <span class="ruby-identifier">employee_pid</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">employee_host</span>
|
462
|
+
104: <span class="ruby-keyword kw">end</span></pre>
|
406
463
|
</div>
|
407
464
|
|
408
465
|
</div>
|
@@ -437,10 +494,10 @@ dispatched)
|
|
437
494
|
<div class="method-source-code"
|
438
495
|
id="cancel-source">
|
439
496
|
<pre>
|
440
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
441
|
-
|
442
|
-
|
443
|
-
|
497
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 83</span>
|
498
|
+
83: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cancel</span>
|
499
|
+
84: <span class="ruby-identifier">mark_as_cancelled</span>
|
500
|
+
85: <span class="ruby-keyword kw">end</span></pre>
|
444
501
|
</div>
|
445
502
|
|
446
503
|
</div>
|
@@ -473,10 +530,10 @@ Has the job been cancelled?
|
|
473
530
|
<div class="method-source-code"
|
474
531
|
id="cancelled--source">
|
475
532
|
<pre>
|
476
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
477
|
-
|
478
|
-
|
479
|
-
|
533
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 88</span>
|
534
|
+
88: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cancelled?</span>
|
535
|
+
89: <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">cancelled_at</span>
|
536
|
+
90: <span class="ruby-keyword kw">end</span></pre>
|
480
537
|
</div>
|
481
538
|
|
482
539
|
</div>
|
@@ -509,10 +566,10 @@ Is the job complete?
|
|
509
566
|
<div class="method-source-code"
|
510
567
|
id="completed--source">
|
511
568
|
<pre>
|
512
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
513
|
-
|
514
|
-
|
515
|
-
|
569
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 77</span>
|
570
|
+
77: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">completed?</span>
|
571
|
+
78: <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">completed_at</span>
|
572
|
+
79: <span class="ruby-keyword kw">end</span></pre>
|
516
573
|
</div>
|
517
574
|
|
518
575
|
</div>
|
@@ -551,34 +608,31 @@ Method used by the boss to dispatch an employee
|
|
551
608
|
17: <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">"Dispatching Job ##{self.id}"</span>
|
552
609
|
18:
|
553
610
|
19: <span class="ruby-identifier">pid</span> = <span class="ruby-identifier">fork</span> <span class="ruby-keyword kw">do</span>
|
554
|
-
20: <span class="ruby-
|
555
|
-
21: <span class="ruby-
|
556
|
-
22:
|
557
|
-
23:
|
558
|
-
24:
|
559
|
-
25:
|
560
|
-
26:
|
561
|
-
27:
|
562
|
-
28:
|
563
|
-
29:
|
564
|
-
30:
|
565
|
-
31:
|
566
|
-
32: <span class="ruby-
|
567
|
-
33: <span class="ruby-keyword kw">
|
568
|
-
34: <span class="ruby-
|
569
|
-
35:
|
570
|
-
36:
|
571
|
-
37:
|
572
|
-
38:
|
573
|
-
39: <span class="ruby-
|
574
|
-
40:
|
575
|
-
41:
|
576
|
-
42:
|
577
|
-
43:
|
578
|
-
44:
|
579
|
-
45:
|
580
|
-
46: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">detach</span>(<span class="ruby-identifier">pid</span>)
|
581
|
-
47: <span class="ruby-keyword kw">end</span></pre>
|
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>
|
612
|
+
21: <span class="ruby-identifier">$0</span> = <span class="ruby-node">"[job_boss employee] job ##{self.id} #{self.path}(#{self.args.join(', ')})"</span>
|
613
|
+
22: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setpriority</span>(<span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-constant">PRIO_PROCESS</span>, <span class="ruby-value">0</span>, <span class="ruby-value">19</span>)
|
614
|
+
23:
|
615
|
+
24: <span class="ruby-keyword kw">begin</span>
|
616
|
+
25: <span class="ruby-identifier">mark_employee</span>
|
617
|
+
26:
|
618
|
+
27: <span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">call_path</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>, *<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">args</span>)
|
619
|
+
28:
|
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
|
+
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
|
+
31: <span class="ruby-identifier">mark_exception</span>(<span class="ruby-identifier">exception</span>)
|
623
|
+
32: <span class="ruby-constant">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
|
+
33: <span class="ruby-keyword kw">ensure</span>
|
625
|
+
34: <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">mark_as_completed</span>
|
626
|
+
35: <span class="ruby-identifier">sleep</span>(<span class="ruby-value">1</span>)
|
627
|
+
36: <span class="ruby-keyword kw">end</span>
|
628
|
+
37:
|
629
|
+
38: <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">"Job ##{self.id} completed, exiting..."</span>
|
630
|
+
39: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">exit</span>
|
631
|
+
40: <span class="ruby-keyword kw">end</span>
|
632
|
+
41: <span class="ruby-keyword kw">end</span>
|
633
|
+
42: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">detach</span>(<span class="ruby-identifier">pid</span>)
|
634
|
+
43: <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>
|
635
|
+
44: <span class="ruby-keyword kw">end</span></pre>
|
582
636
|
</div>
|
583
637
|
|
584
638
|
</div>
|
@@ -612,18 +666,18 @@ that exception with the message and backtrace
|
|
612
666
|
<div class="method-source-code"
|
613
667
|
id="error-source">
|
614
668
|
<pre>
|
615
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
669
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 117</span>
|
670
|
+
117: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">error</span>
|
671
|
+
118: <span class="ruby-comment cmt"># If the error is being called for but the job hasn't been completed, reload</span>
|
672
|
+
119: <span class="ruby-comment cmt"># to check to see if there was a error</span>
|
673
|
+
120: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">completed?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">error_message</span>.<span class="ruby-identifier">nil?</span>
|
674
|
+
121:
|
675
|
+
122: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">error_class</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">error_message</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">error_backtrace</span>
|
676
|
+
123: <span class="ruby-identifier">error</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">error_class</span>).<span class="ruby-identifier">new</span>(<span class="ruby-identifier">error_message</span>)
|
677
|
+
124: <span class="ruby-identifier">error</span>.<span class="ruby-identifier">set_backtrace</span>(<span class="ruby-identifier">error_backtrace</span>)
|
678
|
+
125: <span class="ruby-identifier">error</span>
|
679
|
+
126: <span class="ruby-keyword kw">end</span>
|
680
|
+
127: <span class="ruby-keyword kw">end</span></pre>
|
627
681
|
</div>
|
628
682
|
|
629
683
|
</div>
|
@@ -656,19 +710,19 @@ Clear out the job and put it back onto the queue for processing
|
|
656
710
|
<div class="method-source-code"
|
657
711
|
id="mark-for-redo-source">
|
658
712
|
<pre>
|
659
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
713
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 63</span>
|
714
|
+
63: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_for_redo</span>
|
715
|
+
64: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span>
|
716
|
+
65: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">started_at</span> = <span class="ruby-keyword kw">nil</span>
|
717
|
+
66: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">nil</span>
|
718
|
+
67: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">completed_at</span> = <span class="ruby-keyword kw">nil</span>
|
719
|
+
68: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">status</span> = <span class="ruby-keyword kw">nil</span>
|
720
|
+
69: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">error_message</span> = <span class="ruby-keyword kw">nil</span>
|
721
|
+
70: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">error_backtrace</span> = <span class="ruby-keyword kw">nil</span>
|
722
|
+
71: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">employee_host</span> = <span class="ruby-keyword kw">nil</span>
|
723
|
+
72: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">employee_pid</span> = <span class="ruby-keyword kw">nil</span>
|
724
|
+
73: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">save</span>
|
725
|
+
74: <span class="ruby-keyword kw">end</span></pre>
|
672
726
|
</div>
|
673
727
|
|
674
728
|
</div>
|
@@ -699,16 +753,16 @@ Clear out the job and put it back onto the queue for processing
|
|
699
753
|
<div class="method-source-code"
|
700
754
|
id="result-source">
|
701
755
|
<pre>
|
702
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
756
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 52</span>
|
757
|
+
52: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">result</span>
|
758
|
+
53: <span class="ruby-comment cmt"># If the result is being called for but the job hasn't been completed, reload</span>
|
759
|
+
54: <span class="ruby-comment cmt"># to check to see if there was a result</span>
|
760
|
+
55: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">completed?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">read_attribute</span>(<span class="ruby-value">:result</span>).<span class="ruby-identifier">nil?</span>
|
761
|
+
56:
|
762
|
+
57: <span class="ruby-identifier">value</span> = <span class="ruby-identifier">read_attribute</span>(<span class="ruby-value">:result</span>)
|
763
|
+
58:
|
764
|
+
59: <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">value</span>
|
765
|
+
60: <span class="ruby-keyword kw">end</span></pre>
|
712
766
|
</div>
|
713
767
|
|
714
768
|
</div>
|
@@ -743,10 +797,10 @@ stored as the string “f“
|
|
743
797
|
<div class="method-source-code"
|
744
798
|
id="result--source">
|
745
799
|
<pre>
|
746
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
747
|
-
|
748
|
-
|
749
|
-
|
800
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 48</span>
|
801
|
+
48: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">result=</span>(<span class="ruby-identifier">value</span>)
|
802
|
+
49: <span class="ruby-identifier">write_attribute</span>(<span class="ruby-value">:result</span>, [<span class="ruby-identifier">value</span>])
|
803
|
+
50: <span class="ruby-keyword kw">end</span></pre>
|
750
804
|
</div>
|
751
805
|
|
752
806
|
</div>
|
@@ -779,10 +833,10 @@ Did the job succeed?
|
|
779
833
|
<div class="method-source-code"
|
780
834
|
id="succeeded--source">
|
781
835
|
<pre>
|
782
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
783
|
-
|
784
|
-
|
785
|
-
|
836
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 93</span>
|
837
|
+
93: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">succeeded?</span>
|
838
|
+
94: <span class="ruby-identifier">completed_at</span> <span class="ruby-operator">&&</span> (<span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'success'</span>)
|
839
|
+
95: <span class="ruby-keyword kw">end</span></pre>
|
786
840
|
</div>
|
787
841
|
|
788
842
|
</div>
|
@@ -815,10 +869,14 @@ How long did the job take?
|
|
815
869
|
<div class="method-source-code"
|
816
870
|
id="time-taken-source">
|
817
871
|
<pre>
|
818
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
819
|
-
|
820
|
-
|
821
|
-
|
872
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 107</span>
|
873
|
+
107: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">time_taken</span>
|
874
|
+
108: <span class="ruby-comment cmt"># If the #time_taken method is being called for but the job doesn't seem to have started/completed</span>
|
875
|
+
109: <span class="ruby-comment cmt"># reload to see if it has</span>
|
876
|
+
110: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">started_at</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">completed_at</span>.<span class="ruby-identifier">nil?</span>
|
877
|
+
111:
|
878
|
+
112: <span class="ruby-identifier">completed_at</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">started_at</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">completed_at</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">started_at</span>
|
879
|
+
113: <span class="ruby-keyword kw">end</span></pre>
|
822
880
|
</div>
|
823
881
|
|
824
882
|
</div>
|
@@ -855,10 +913,10 @@ How long did the job take?
|
|
855
913
|
<div class="method-source-code"
|
856
914
|
id="mark-as-cancelled-source">
|
857
915
|
<pre>
|
858
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
859
|
-
|
860
|
-
|
861
|
-
|
916
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 175</span>
|
917
|
+
175: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_as_cancelled</span>
|
918
|
+
176: <span class="ruby-identifier">update_attributes</span>(<span class="ruby-value">:cancelled_at</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>)
|
919
|
+
177: <span class="ruby-keyword kw">end</span></pre>
|
862
920
|
</div>
|
863
921
|
|
864
922
|
</div>
|
@@ -889,12 +947,12 @@ How long did the job take?
|
|
889
947
|
<div class="method-source-code"
|
890
948
|
id="mark-as-completed-source">
|
891
949
|
<pre>
|
892
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
950
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 189</span>
|
951
|
+
189: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_as_completed</span>
|
952
|
+
190: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">'success'</span>
|
953
|
+
191: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">completed_at</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
|
954
|
+
192: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">save</span>
|
955
|
+
193: <span class="ruby-keyword kw">end</span></pre>
|
898
956
|
</div>
|
899
957
|
|
900
958
|
</div>
|
@@ -925,10 +983,10 @@ How long did the job take?
|
|
925
983
|
<div class="method-source-code"
|
926
984
|
id="mark-as-started-source">
|
927
985
|
<pre>
|
928
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
929
|
-
|
930
|
-
|
931
|
-
|
986
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 171</span>
|
987
|
+
171: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_as_started</span>
|
988
|
+
172: <span class="ruby-identifier">update_attributes</span>(<span class="ruby-value">:started_at</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>)
|
989
|
+
173: <span class="ruby-keyword kw">end</span></pre>
|
932
990
|
</div>
|
933
991
|
|
934
992
|
</div>
|
@@ -959,12 +1017,12 @@ How long did the job take?
|
|
959
1017
|
<div class="method-source-code"
|
960
1018
|
id="mark-employee-source">
|
961
1019
|
<pre>
|
962
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
1020
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 179</span>
|
1021
|
+
179: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_employee</span>
|
1022
|
+
180: <span class="ruby-identifier">require</span> <span class="ruby-value str">'socket'</span>
|
1023
|
+
181: <span class="ruby-identifier">update_attributes</span>(<span class="ruby-value">:employee_host</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">gethostname</span>,
|
1024
|
+
182: <span class="ruby-value">:employee_pid</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Process</span>.<span class="ruby-identifier">pid</span>)
|
1025
|
+
183: <span class="ruby-keyword kw">end</span></pre>
|
968
1026
|
</div>
|
969
1027
|
|
970
1028
|
</div>
|
@@ -995,10 +1053,10 @@ How long did the job take?
|
|
995
1053
|
<div class="method-source-code"
|
996
1054
|
id="mark-exception-source">
|
997
1055
|
<pre>
|
998
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1056
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 185</span>
|
1057
|
+
185: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_exception</span>(<span class="ruby-identifier">exception</span>)
|
1058
|
+
186: <span class="ruby-identifier">update_attributes</span>(<span class="ruby-value">:status</span> =<span class="ruby-operator">></span> <span class="ruby-value str">'error'</span>, <span class="ruby-value">:error_class</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-value">:error_message</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">message</span>, <span class="ruby-value">:error_backtrace</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">backtrace</span>)
|
1059
|
+
187: <span class="ruby-keyword kw">end</span></pre>
|
1002
1060
|
</div>
|
1003
1061
|
|
1004
1062
|
</div>
|