job_boss 0.2 → 0.4
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 +25 -2
- data/Rakefile +21 -8
- data/bin/job_boss +1 -0
- data/doc/ActiveSupport/TestCase.html +584 -0
- data/doc/{Passenger.html → ActiveSupport.html} +10 -30
- data/doc/CreateJobs.html +31 -16
- data/doc/{Mongrel.html → DaemonTest.html} +23 -39
- data/doc/JobBoss/Boss.html +466 -68
- data/doc/JobBoss/Config.html +77 -39
- data/doc/JobBoss/Job.html +375 -97
- data/doc/JobBoss/Queuer.html +35 -21
- data/doc/JobBoss.html +14 -311
- data/doc/{ActiveRecord.html → MathJobs.html} +66 -36
- data/doc/Rakefile.html +43 -9
- data/doc/SleepJobs.html +251 -0
- data/doc/{PhusionPassenger.html → StringJobs.html} +66 -38
- data/doc/bin/job_boss.html +1 -1
- data/doc/created.rid +14 -8
- data/doc/index.html +63 -7
- data/doc/lib/job_boss/boss_rb.html +5 -1
- data/doc/lib/job_boss/{configuror_rb.html → config_rb.html} +2 -2
- data/doc/lib/job_boss/job_rb.html +3 -1
- data/doc/lib/job_boss/queuer_rb.html +1 -1
- data/doc/lib/migrate_rb.html +1 -1
- data/doc/{vendor/spawn/lib/spawn_rb.html → test/app_root/app/jobs/math_jobs_rb.html} +7 -7
- data/doc/{vendor/spawn/lib/patches_rb.html → test/app_root/app/jobs/sleep_jobs_rb.html} +8 -12
- data/doc/test/app_root/app/jobs/string_jobs_rb.html +52 -0
- data/doc/test/test_helper_rb.html +62 -0
- data/doc/{vendor/spawn/init_rb.html → test/unit/daemon_test_rb.html} +3 -3
- data/doc/test/unit/job_test_rb.html +60 -0
- data/job_boss.gemspec +3 -2
- data/lib/job_boss/boss.rb +29 -7
- data/lib/job_boss/config.rb +49 -0
- data/lib/job_boss/job.rb +57 -13
- data/lib/migrate.rb +3 -1
- data/test/app_root/app/jobs/math_jobs.rb +5 -0
- data/test/app_root/app/jobs/sleep_jobs.rb +9 -0
- data/test/app_root/app/jobs/string_jobs.rb +5 -0
- data/test/app_root/config/database.yml +22 -0
- data/test/test_helper.rb +113 -0
- data/test/unit/daemon_test.rb +29 -0
- data/test/unit/job_test.rb +73 -0
- metadata +46 -27
- data/doc/ActiveRecord/Base.html +0 -343
- data/doc/Mongrel/HttpServer.html +0 -275
- data/doc/Passenger/Railz/RequestHandler.html +0 -271
- data/doc/Passenger/Railz.html +0 -185
- data/doc/PhusionPassenger/Rack/RequestHandler.html +0 -271
- data/doc/PhusionPassenger/Rack.html +0 -185
- data/doc/PhusionPassenger/Railz/RequestHandler.html +0 -271
- data/doc/PhusionPassenger/Railz.html +0 -185
- data/doc/Spawn/SpawnId.html +0 -276
- data/doc/Spawn.html +0 -742
- data/doc/vendor/spawn/CHANGELOG.html +0 -275
- data/doc/vendor/spawn/LICENSE.html +0 -151
- data/lib/job_boss/configuror.rb +0 -40
data/doc/JobBoss/Job.html
CHANGED
@@ -73,6 +73,12 @@
|
|
73
73
|
|
74
74
|
<li><a href="#method-c-pending_paths">::pending_paths</a></li>
|
75
75
|
|
76
|
+
<li><a href="#method-c-result_hash">::result_hash</a></li>
|
77
|
+
|
78
|
+
<li><a href="#method-c-wait_for_jobs">::wait_for_jobs</a></li>
|
79
|
+
|
80
|
+
<li><a href="#method-i-assigned%3F">#assigned?</a></li>
|
81
|
+
|
76
82
|
<li><a href="#method-i-cancel">#cancel</a></li>
|
77
83
|
|
78
84
|
<li><a href="#method-i-cancelled%3F">#cancelled?</a></li>
|
@@ -81,6 +87,8 @@
|
|
81
87
|
|
82
88
|
<li><a href="#method-i-dispatch">#dispatch</a></li>
|
83
89
|
|
90
|
+
<li><a href="#method-i-error">#error</a></li>
|
91
|
+
|
84
92
|
<li><a href="#method-i-mark_as_cancelled">#mark_as_cancelled</a></li>
|
85
93
|
|
86
94
|
<li><a href="#method-i-mark_as_completed">#mark_as_completed</a></li>
|
@@ -93,6 +101,10 @@
|
|
93
101
|
|
94
102
|
<li><a href="#method-i-mark_for_redo">#mark_for_redo</a></li>
|
95
103
|
|
104
|
+
<li><a href="#method-i-result">#result</a></li>
|
105
|
+
|
106
|
+
<li><a href="#method-i-result%3D">#result=</a></li>
|
107
|
+
|
96
108
|
<li><a href="#method-i-succeeded%3F">#succeeded?</a></li>
|
97
109
|
|
98
110
|
<li><a href="#method-i-time_taken">#time_taken</a></li>
|
@@ -143,8 +155,20 @@
|
|
143
155
|
|
144
156
|
<li><a href="../JobBoss/Queuer.html">JobBoss::Queuer</a></li>
|
145
157
|
|
158
|
+
<li><a href="../ActiveSupport.html">ActiveSupport</a></li>
|
159
|
+
|
160
|
+
<li><a href="../ActiveSupport/TestCase.html">ActiveSupport::TestCase</a></li>
|
161
|
+
|
146
162
|
<li><a href="../CreateJobs.html">CreateJobs</a></li>
|
147
163
|
|
164
|
+
<li><a href="../DaemonTest.html">DaemonTest</a></li>
|
165
|
+
|
166
|
+
<li><a href="../MathJobs.html">MathJobs</a></li>
|
167
|
+
|
168
|
+
<li><a href="../SleepJobs.html">SleepJobs</a></li>
|
169
|
+
|
170
|
+
<li><a href="../StringJobs.html">StringJobs</a></li>
|
171
|
+
|
148
172
|
</ul>
|
149
173
|
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
150
174
|
</div>
|
@@ -168,6 +192,96 @@
|
|
168
192
|
|
169
193
|
<!-- Methods -->
|
170
194
|
|
195
|
+
<div id="public-class-method-details" class="method-section section">
|
196
|
+
<h3 class="section-header">Public Class Methods</h3>
|
197
|
+
|
198
|
+
|
199
|
+
<div id="result-hash-method" class="method-detail ">
|
200
|
+
<a name="method-c-result_hash"></a>
|
201
|
+
|
202
|
+
<div class="method-heading">
|
203
|
+
|
204
|
+
<span class="method-name">result_hash</span><span
|
205
|
+
class="method-args">(jobs)</span>
|
206
|
+
<span class="method-click-advice">click to toggle source</span>
|
207
|
+
|
208
|
+
</div>
|
209
|
+
|
210
|
+
<div class="method-description">
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
<div class="method-source-code"
|
217
|
+
id="result-hash-source">
|
218
|
+
<pre>
|
219
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 140</span>
|
220
|
+
140: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">result_hash</span>(<span class="ruby-identifier">jobs</span>)
|
221
|
+
141: <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>)
|
222
|
+
142:
|
223
|
+
143: <span class="ruby-comment cmt"># the #result method automatically reloads the result here if needed but this will</span>
|
224
|
+
144: <span class="ruby-comment cmt"># do it in one SQL call</span>
|
225
|
+
145: <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>))
|
226
|
+
146:
|
227
|
+
147: <span class="ruby-identifier">require</span> <span class="ruby-value str">'yaml'</span>
|
228
|
+
148: <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>
|
229
|
+
149: <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>)
|
230
|
+
150: <span class="ruby-keyword kw">end</span>
|
231
|
+
151: <span class="ruby-keyword kw">end</span></pre>
|
232
|
+
</div>
|
233
|
+
|
234
|
+
</div>
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
</div>
|
240
|
+
|
241
|
+
|
242
|
+
<div id="wait-for-jobs-method" class="method-detail ">
|
243
|
+
<a name="method-c-wait_for_jobs"></a>
|
244
|
+
|
245
|
+
<div class="method-heading">
|
246
|
+
|
247
|
+
<span class="method-name">wait_for_jobs</span><span
|
248
|
+
class="method-args">(jobs, sleep_interval = 0.5)</span>
|
249
|
+
<span class="method-click-advice">click to toggle source</span>
|
250
|
+
|
251
|
+
</div>
|
252
|
+
|
253
|
+
<div class="method-description">
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
<div class="method-source-code"
|
260
|
+
id="wait-for-jobs-source">
|
261
|
+
<pre>
|
262
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 129</span>
|
263
|
+
129: <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>)
|
264
|
+
130: <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>)
|
265
|
+
131:
|
266
|
+
132: <span class="ruby-identifier">ids</span> = <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">collect</span>(&<span class="ruby-value">:id</span>)
|
267
|
+
133: <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>
|
268
|
+
134: <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">sleep_interval</span>)
|
269
|
+
135: <span class="ruby-keyword kw">end</span>
|
270
|
+
136:
|
271
|
+
137: <span class="ruby-keyword kw">true</span>
|
272
|
+
138: <span class="ruby-keyword kw">end</span></pre>
|
273
|
+
</div>
|
274
|
+
|
275
|
+
</div>
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
</div>
|
281
|
+
|
282
|
+
|
283
|
+
</div>
|
284
|
+
|
171
285
|
<div id="private-class-method-details" class="method-section section">
|
172
286
|
<h3 class="section-header">Private Class Methods</h3>
|
173
287
|
|
@@ -192,23 +306,23 @@
|
|
192
306
|
<div class="method-source-code"
|
193
307
|
id="call-path-source">
|
194
308
|
<pre>
|
195
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
309
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 181</span>
|
310
|
+
181: <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>)
|
311
|
+
182: <span class="ruby-identifier">require</span> <span class="ruby-value str">'active_support'</span>
|
312
|
+
183:
|
313
|
+
184: <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>)
|
314
|
+
185: <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>)
|
315
|
+
186:
|
316
|
+
187: <span class="ruby-identifier">controller_object</span> = <span class="ruby-keyword kw">begin</span>
|
317
|
+
188: <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>
|
318
|
+
189: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
|
319
|
+
190: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"Invalid controller"</span>
|
320
|
+
191: <span class="ruby-keyword kw">end</span>
|
321
|
+
192:
|
322
|
+
193: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"Invalid path 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>)
|
323
|
+
194:
|
324
|
+
195: <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>)
|
325
|
+
196: <span class="ruby-keyword kw">end</span></pre>
|
212
326
|
</div>
|
213
327
|
|
214
328
|
</div>
|
@@ -239,10 +353,10 @@
|
|
239
353
|
<div class="method-source-code"
|
240
354
|
id="pending-paths-source">
|
241
355
|
<pre>
|
242
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
243
|
-
|
244
|
-
|
245
|
-
|
356
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 198</span>
|
357
|
+
198: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pending_paths</span>
|
358
|
+
199: <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>)
|
359
|
+
200: <span class="ruby-keyword kw">end</span></pre>
|
246
360
|
</div>
|
247
361
|
|
248
362
|
</div>
|
@@ -259,6 +373,46 @@
|
|
259
373
|
<h3 class="section-header">Public Instance Methods</h3>
|
260
374
|
|
261
375
|
|
376
|
+
<div id="assigned--method" class="method-detail ">
|
377
|
+
<a name="method-i-assigned%3F"></a>
|
378
|
+
|
379
|
+
<div class="method-heading">
|
380
|
+
|
381
|
+
<span class="method-name">assigned?</span><span
|
382
|
+
class="method-args">()</span>
|
383
|
+
<span class="method-click-advice">click to toggle source</span>
|
384
|
+
|
385
|
+
</div>
|
386
|
+
|
387
|
+
<div class="method-description">
|
388
|
+
|
389
|
+
<p>
|
390
|
+
Has the job been assigned to an employee?
|
391
|
+
</p>
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
<div class="method-source-code"
|
396
|
+
id="assigned--source">
|
397
|
+
<pre>
|
398
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 101</span>
|
399
|
+
101: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assigned?</span>
|
400
|
+
102: <span class="ruby-comment cmt"># If the #assigned? method is being called for but the job hasn't been completed, reload</span>
|
401
|
+
103: <span class="ruby-comment cmt"># to check to see if it has been assigned</span>
|
402
|
+
104: <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>
|
403
|
+
105:
|
404
|
+
106: <span class="ruby-identifier">employee_pid</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">employee_host</span>
|
405
|
+
107: <span class="ruby-keyword kw">end</span></pre>
|
406
|
+
</div>
|
407
|
+
|
408
|
+
</div>
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
</div>
|
414
|
+
|
415
|
+
|
262
416
|
<div id="cancel-method" class="method-detail ">
|
263
417
|
<a name="method-i-cancel"></a>
|
264
418
|
|
@@ -283,10 +437,10 @@ dispatched)
|
|
283
437
|
<div class="method-source-code"
|
284
438
|
id="cancel-source">
|
285
439
|
<pre>
|
286
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
287
|
-
|
288
|
-
|
289
|
-
|
440
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 86</span>
|
441
|
+
86: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cancel</span>
|
442
|
+
87: <span class="ruby-identifier">mark_as_cancelled</span>
|
443
|
+
88: <span class="ruby-keyword kw">end</span></pre>
|
290
444
|
</div>
|
291
445
|
|
292
446
|
</div>
|
@@ -319,10 +473,10 @@ Has the job been cancelled?
|
|
319
473
|
<div class="method-source-code"
|
320
474
|
id="cancelled--source">
|
321
475
|
<pre>
|
322
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
323
|
-
|
324
|
-
|
325
|
-
|
476
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 91</span>
|
477
|
+
91: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cancelled?</span>
|
478
|
+
92: <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">cancelled_at</span>
|
479
|
+
93: <span class="ruby-keyword kw">end</span></pre>
|
326
480
|
</div>
|
327
481
|
|
328
482
|
</div>
|
@@ -355,10 +509,10 @@ Is the job complete?
|
|
355
509
|
<div class="method-source-code"
|
356
510
|
id="completed--source">
|
357
511
|
<pre>
|
358
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
359
|
-
|
360
|
-
|
361
|
-
|
512
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 80</span>
|
513
|
+
80: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">completed?</span>
|
514
|
+
81: <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">completed_at</span>
|
515
|
+
82: <span class="ruby-keyword kw">end</span></pre>
|
362
516
|
</div>
|
363
517
|
|
364
518
|
</div>
|
@@ -394,10 +548,10 @@ Method used by the boss to dispatch an employee
|
|
394
548
|
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 15</span>
|
395
549
|
15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dispatch</span>
|
396
550
|
16: <span class="ruby-identifier">mark_as_started</span>
|
397
|
-
17: <span class="ruby-identifier">
|
551
|
+
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>
|
398
552
|
18:
|
399
553
|
19: <span class="ruby-identifier">pid</span> = <span class="ruby-identifier">fork</span> <span class="ruby-keyword kw">do</span>
|
400
|
-
20: <span class="ruby-identifier">$0</span> = <span class="ruby-node">"job_boss
|
554
|
+
20: <span class="ruby-identifier">$0</span> = <span class="ruby-node">"[job_boss] employee (job ##{self.id})"</span>
|
401
555
|
21: <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>)
|
402
556
|
22:
|
403
557
|
23: <span class="ruby-keyword kw">begin</span>
|
@@ -407,23 +561,69 @@ Method used by the boss to dispatch an employee
|
|
407
561
|
27: <span class="ruby-identifier">mark_for_redo</span>
|
408
562
|
28: <span class="ruby-keyword kw">end</span>
|
409
563
|
29:
|
410
|
-
30: <span class="ruby-identifier">
|
411
|
-
31:
|
412
|
-
32:
|
413
|
-
33:
|
414
|
-
34: <span class="ruby-identifier">
|
415
|
-
35:
|
416
|
-
36:
|
417
|
-
37:
|
418
|
-
38:
|
419
|
-
39:
|
420
|
-
40:
|
421
|
-
41: <span class="ruby-constant">
|
422
|
-
42:
|
423
|
-
43:
|
424
|
-
44:
|
425
|
-
45:
|
426
|
-
46:
|
564
|
+
30: <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>)
|
565
|
+
31:
|
566
|
+
32: <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>)
|
567
|
+
33: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">exception</span>
|
568
|
+
34: <span class="ruby-identifier">mark_exception</span>(<span class="ruby-identifier">exception</span>)
|
569
|
+
35: <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>
|
570
|
+
36: <span class="ruby-keyword kw">ensure</span>
|
571
|
+
37: <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">mark_as_completed</span>
|
572
|
+
38: <span class="ruby-identifier">sleep</span>(<span class="ruby-value">1</span>)
|
573
|
+
39: <span class="ruby-keyword kw">end</span>
|
574
|
+
40:
|
575
|
+
41: <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>
|
576
|
+
42: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">exit</span>
|
577
|
+
43: <span class="ruby-keyword kw">end</span>
|
578
|
+
44: <span class="ruby-keyword kw">end</span>
|
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>
|
582
|
+
</div>
|
583
|
+
|
584
|
+
</div>
|
585
|
+
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
</div>
|
590
|
+
|
591
|
+
|
592
|
+
<div id="error-method" class="method-detail ">
|
593
|
+
<a name="method-i-error"></a>
|
594
|
+
|
595
|
+
<div class="method-heading">
|
596
|
+
|
597
|
+
<span class="method-name">error</span><span
|
598
|
+
class="method-args">()</span>
|
599
|
+
<span class="method-click-advice">click to toggle source</span>
|
600
|
+
|
601
|
+
</div>
|
602
|
+
|
603
|
+
<div class="method-description">
|
604
|
+
|
605
|
+
<p>
|
606
|
+
If the job raised an exception, this method will return the instance of
|
607
|
+
that exception with the message and backtrace
|
608
|
+
</p>
|
609
|
+
|
610
|
+
|
611
|
+
|
612
|
+
<div class="method-source-code"
|
613
|
+
id="error-source">
|
614
|
+
<pre>
|
615
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 116</span>
|
616
|
+
116: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">error</span>
|
617
|
+
117: <span class="ruby-comment cmt"># If the error is being called for but the job hasn't been completed, reload</span>
|
618
|
+
118: <span class="ruby-comment cmt"># to check to see if there was a error</span>
|
619
|
+
119: <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>
|
620
|
+
120:
|
621
|
+
121: <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>
|
622
|
+
122: <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>)
|
623
|
+
123: <span class="ruby-identifier">error</span>.<span class="ruby-identifier">set_backtrace</span>(<span class="ruby-identifier">error_backtrace</span>)
|
624
|
+
124: <span class="ruby-identifier">error</span>
|
625
|
+
125: <span class="ruby-keyword kw">end</span>
|
626
|
+
126: <span class="ruby-keyword kw">end</span></pre>
|
427
627
|
</div>
|
428
628
|
|
429
629
|
</div>
|
@@ -456,19 +656,97 @@ Clear out the job and put it back onto the queue for processing
|
|
456
656
|
<div class="method-source-code"
|
457
657
|
id="mark-for-redo-source">
|
458
658
|
<pre>
|
459
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
659
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 66</span>
|
660
|
+
66: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_for_redo</span>
|
661
|
+
67: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span>
|
662
|
+
68: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">started_at</span> = <span class="ruby-keyword kw">nil</span>
|
663
|
+
69: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">nil</span>
|
664
|
+
70: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">completed_at</span> = <span class="ruby-keyword kw">nil</span>
|
665
|
+
71: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">status</span> = <span class="ruby-keyword kw">nil</span>
|
666
|
+
72: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">error_message</span> = <span class="ruby-keyword kw">nil</span>
|
667
|
+
73: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">error_backtrace</span> = <span class="ruby-keyword kw">nil</span>
|
668
|
+
74: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">employee_host</span> = <span class="ruby-keyword kw">nil</span>
|
669
|
+
75: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">employee_pid</span> = <span class="ruby-keyword kw">nil</span>
|
670
|
+
76: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">save</span>
|
671
|
+
77: <span class="ruby-keyword kw">end</span></pre>
|
672
|
+
</div>
|
673
|
+
|
674
|
+
</div>
|
675
|
+
|
676
|
+
|
677
|
+
|
678
|
+
|
679
|
+
</div>
|
680
|
+
|
681
|
+
|
682
|
+
<div id="result-method" class="method-detail ">
|
683
|
+
<a name="method-i-result"></a>
|
684
|
+
|
685
|
+
<div class="method-heading">
|
686
|
+
|
687
|
+
<span class="method-name">result</span><span
|
688
|
+
class="method-args">()</span>
|
689
|
+
<span class="method-click-advice">click to toggle source</span>
|
690
|
+
|
691
|
+
</div>
|
692
|
+
|
693
|
+
<div class="method-description">
|
694
|
+
|
695
|
+
|
696
|
+
|
697
|
+
|
698
|
+
|
699
|
+
<div class="method-source-code"
|
700
|
+
id="result-source">
|
701
|
+
<pre>
|
702
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 55</span>
|
703
|
+
55: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">result</span>
|
704
|
+
56: <span class="ruby-comment cmt"># If the result is being called for but the job hasn't been completed, reload</span>
|
705
|
+
57: <span class="ruby-comment cmt"># to check to see if there was a result</span>
|
706
|
+
58: <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>
|
707
|
+
59:
|
708
|
+
60: <span class="ruby-identifier">value</span> = <span class="ruby-identifier">read_attribute</span>(<span class="ruby-value">:result</span>)
|
709
|
+
61:
|
710
|
+
62: <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>
|
711
|
+
63: <span class="ruby-keyword kw">end</span></pre>
|
712
|
+
</div>
|
713
|
+
|
714
|
+
</div>
|
715
|
+
|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
</div>
|
720
|
+
|
721
|
+
|
722
|
+
<div id="result--method" class="method-detail ">
|
723
|
+
<a name="method-i-result%3D"></a>
|
724
|
+
|
725
|
+
<div class="method-heading">
|
726
|
+
|
727
|
+
<span class="method-name">result=</span><span
|
728
|
+
class="method-args">(value)</span>
|
729
|
+
<span class="method-click-advice">click to toggle source</span>
|
730
|
+
|
731
|
+
</div>
|
732
|
+
|
733
|
+
<div class="method-description">
|
734
|
+
|
735
|
+
<p>
|
736
|
+
Store result as first and only value of an array so that the value always
|
737
|
+
gets serialized Was having issues with the boolean value of false getting
|
738
|
+
stored as the string “f“
|
739
|
+
</p>
|
740
|
+
|
741
|
+
|
742
|
+
|
743
|
+
<div class="method-source-code"
|
744
|
+
id="result--source">
|
745
|
+
<pre>
|
746
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 51</span>
|
747
|
+
51: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">result=</span>(<span class="ruby-identifier">value</span>)
|
748
|
+
52: <span class="ruby-identifier">write_attribute</span>(<span class="ruby-value">:result</span>, [<span class="ruby-identifier">value</span>])
|
749
|
+
53: <span class="ruby-keyword kw">end</span></pre>
|
472
750
|
</div>
|
473
751
|
|
474
752
|
</div>
|
@@ -501,10 +779,10 @@ Did the job succeed?
|
|
501
779
|
<div class="method-source-code"
|
502
780
|
id="succeeded--source">
|
503
781
|
<pre>
|
504
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
505
|
-
|
506
|
-
|
507
|
-
|
782
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 96</span>
|
783
|
+
96: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">succeeded?</span>
|
784
|
+
97: <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>)
|
785
|
+
98: <span class="ruby-keyword kw">end</span></pre>
|
508
786
|
</div>
|
509
787
|
|
510
788
|
</div>
|
@@ -537,10 +815,10 @@ How long did the job take?
|
|
537
815
|
<div class="method-source-code"
|
538
816
|
id="time-taken-source">
|
539
817
|
<pre>
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
818
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 110</span>
|
819
|
+
110: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">time_taken</span>
|
820
|
+
111: <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>
|
821
|
+
112: <span class="ruby-keyword kw">end</span></pre>
|
544
822
|
</div>
|
545
823
|
|
546
824
|
</div>
|
@@ -577,10 +855,10 @@ How long did the job take?
|
|
577
855
|
<div class="method-source-code"
|
578
856
|
id="mark-as-cancelled-source">
|
579
857
|
<pre>
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
858
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 160</span>
|
859
|
+
160: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_as_cancelled</span>
|
860
|
+
161: <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>)
|
861
|
+
162: <span class="ruby-keyword kw">end</span></pre>
|
584
862
|
</div>
|
585
863
|
|
586
864
|
</div>
|
@@ -611,12 +889,12 @@ How long did the job take?
|
|
611
889
|
<div class="method-source-code"
|
612
890
|
id="mark-as-completed-source">
|
613
891
|
<pre>
|
614
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
892
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 174</span>
|
893
|
+
174: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_as_completed</span>
|
894
|
+
175: <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>
|
895
|
+
176: <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>
|
896
|
+
177: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">save</span>
|
897
|
+
178: <span class="ruby-keyword kw">end</span></pre>
|
620
898
|
</div>
|
621
899
|
|
622
900
|
</div>
|
@@ -647,10 +925,10 @@ How long did the job take?
|
|
647
925
|
<div class="method-source-code"
|
648
926
|
id="mark-as-started-source">
|
649
927
|
<pre>
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
928
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 156</span>
|
929
|
+
156: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_as_started</span>
|
930
|
+
157: <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>)
|
931
|
+
158: <span class="ruby-keyword kw">end</span></pre>
|
654
932
|
</div>
|
655
933
|
|
656
934
|
</div>
|
@@ -681,12 +959,12 @@ How long did the job take?
|
|
681
959
|
<div class="method-source-code"
|
682
960
|
id="mark-employee-source">
|
683
961
|
<pre>
|
684
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
962
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 164</span>
|
963
|
+
164: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_employee</span>
|
964
|
+
165: <span class="ruby-identifier">require</span> <span class="ruby-value str">'socket'</span>
|
965
|
+
166: <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>,
|
966
|
+
167: <span class="ruby-value">:employee_pid</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Process</span>.<span class="ruby-identifier">pid</span>)
|
967
|
+
168: <span class="ruby-keyword kw">end</span></pre>
|
690
968
|
</div>
|
691
969
|
|
692
970
|
</div>
|
@@ -717,10 +995,10 @@ How long did the job take?
|
|
717
995
|
<div class="method-source-code"
|
718
996
|
id="mark-exception-source">
|
719
997
|
<pre>
|
720
|
-
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line
|
721
|
-
|
722
|
-
|
723
|
-
|
998
|
+
<span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 170</span>
|
999
|
+
170: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_exception</span>(<span class="ruby-identifier">exception</span>)
|
1000
|
+
171: <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>)
|
1001
|
+
172: <span class="ruby-keyword kw">end</span></pre>
|
724
1002
|
</div>
|
725
1003
|
|
726
1004
|
</div>
|