job_boss 0.5.0 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/README.markdown +39 -7
  2. data/bin/job_boss +4 -2
  3. data/doc/ActiveSupport/TestCase.html +106 -87
  4. data/doc/ActiveSupport.html +6 -0
  5. data/doc/CreateJobs.html +17 -5
  6. data/doc/DaemonTest.html +6 -0
  7. data/doc/Gemfile.html +128 -0
  8. data/doc/JobBoss/Boss.html +193 -144
  9. data/doc/JobBoss/Config.html +8 -2
  10. data/doc/JobBoss/Job.html +224 -166
  11. data/doc/JobBoss/Queuer.html +25 -11
  12. data/doc/JobBoss.html +9 -0
  13. data/doc/MIT-LICENSE.html +137 -0
  14. data/doc/MathJobs.html +6 -0
  15. data/doc/Penguin.html +223 -0
  16. data/doc/Rakefile.html +6 -0
  17. data/doc/SleepJobs.html +6 -0
  18. data/doc/StringJobs.html +7 -1
  19. data/doc/bin/job_boss.html +3 -1
  20. data/doc/created.rid +17 -11
  21. data/doc/images/brick.png +0 -0
  22. data/doc/images/brick_link.png +0 -0
  23. data/doc/images/bug.png +0 -0
  24. data/doc/images/bullet_black.png +0 -0
  25. data/doc/images/bullet_toggle_minus.png +0 -0
  26. data/doc/images/bullet_toggle_plus.png +0 -0
  27. data/doc/images/date.png +0 -0
  28. data/doc/images/find.png +0 -0
  29. data/doc/images/loadingAnimation.gif +0 -0
  30. data/doc/images/macFFBgHack.png +0 -0
  31. data/doc/images/package.png +0 -0
  32. data/doc/images/page_green.png +0 -0
  33. data/doc/images/page_white_text.png +0 -0
  34. data/doc/images/page_white_width.png +0 -0
  35. data/doc/images/plugin.png +0 -0
  36. data/doc/images/ruby.png +0 -0
  37. data/doc/images/tag_green.png +0 -0
  38. data/doc/images/wrench.png +0 -0
  39. data/doc/images/wrench_orange.png +0 -0
  40. data/doc/images/zoom.png +0 -0
  41. data/doc/index.html +12 -0
  42. data/doc/init_rb.html +54 -0
  43. data/doc/js/darkfish.js +116 -0
  44. data/doc/js/jquery.js +32 -0
  45. data/doc/js/quicksearch.js +114 -0
  46. data/doc/js/thickbox-compressed.js +10 -0
  47. data/doc/lib/job_boss/boss_rb.html +1 -1
  48. data/doc/lib/job_boss/config_rb.html +1 -1
  49. data/doc/lib/job_boss/job_rb.html +1 -1
  50. data/doc/lib/job_boss/queuer_rb.html +1 -1
  51. data/doc/lib/job_boss_rb.html +56 -0
  52. data/doc/lib/migrate_rb.html +1 -1
  53. data/doc/test/app_root/app/jobs/string_jobs_rb.html +1 -1
  54. data/doc/test/app_root/app/models/penguin_rb.html +52 -0
  55. data/doc/test/app_root/config/environment_rb.html +56 -0
  56. data/doc/test/test_helper_rb.html +3 -1
  57. data/doc/test/unit/job_test_rb.html +2 -4
  58. data/job_boss.gemspec +1 -1
  59. data/lib/job_boss/config.rb +2 -2
  60. data/lib/job_boss/job.rb +22 -2
  61. data/lib/job_boss/queuer.rb +10 -2
  62. data/lib/migrate.rb +6 -0
  63. data/test/app_root/app/models/penguin.rb +9 -0
  64. data/test/app_root/config/database.yml +3 -3
  65. data/test/app_root/config/environment.rb +3 -0
  66. data/test/test_helper.rb +6 -4
  67. data/test/unit/job_test.rb +33 -17
  68. metadata +38 -9
data/README.markdown CHANGED
@@ -2,12 +2,19 @@
2
2
 
3
3
  ## Credits
4
4
 
5
- The idea for this gem came from trying to use working/starling and not having much success with stability. After some discussions with my colleagues (Neil Cook and Justin Hahn) and some good ideas, I created job_boss
5
+ The idea for this gem came from trying to use working/starling and not having much success with stability. I created job_boss after some discussions with my colleagues (Neil Cook and Justin Hahn). Thanks also to my employer, [RBM Technologies](http://www.rbmtechnologies.com) for letting me take some of this work open-source.
6
6
 
7
7
  ## Purpose
8
8
 
9
9
  job_boss allows you to have a daemon much in the same way as workling which allows you to process a series of jobs asynchronously. job_boss, however, uses ActiveRecord to store queued job requests in a database thus simplifying dependencies. This allows for us to process chunks of work in parallel, across multiple servers, without needing much setup
10
10
 
11
+ ## Overview
12
+
13
+ * job_boss uses ActiveRecord to store/poll it's queue. It's not dependent on Rails, but if it sees that it's being run in a Rails environment, it will automatically load the environment.rb file
14
+ * Loading up the environment.rb file isn't a big deal because job_boss's model has a main "boss" process which is a deamon. The boss forks employees as needed to execute jobs.
15
+ * Employees only exist for the span of one job, so there's less concern about a build up in memory from leaks (not that we shouldn't be addressing leaks...)
16
+ * The boss is independent and always polling, so it can look for jobs which have been marked an cancelled and kill the employee during processing
17
+
11
18
  ## Usage
12
19
 
13
20
  Add the gem to your Gemfile
@@ -27,6 +34,17 @@ Create a directory to store classes which define code which can be executed by t
27
34
  end
28
35
  end
29
36
 
37
+ If you're using Rails, much of the logic that you'll want to queue may already be in models or other application classes. You can queue class methods rather that needing to wrap them in a Job class:
38
+
39
+ # app/models/article.rb
40
+ class Article < ActiveRecord::Base
41
+ class << self
42
+ def refresh_cache(article_ids)
43
+ # code to refresh article cache
44
+ end
45
+ end
46
+ end
47
+
30
48
  Start up your boss:
31
49
 
32
50
  job_boss start -- <options>
@@ -46,16 +64,29 @@ But since you don't want to do that right now, it looks something like this:
46
64
  -s, --sleep-interval INTERVAL Number of seconds for the boss to sleep between checks of the queue (default 0.5)
47
65
  -c, --employee-limit LIMIT Maximum number of employees (default 4)
48
66
 
49
- From your Rails code or in a console (this functionality should probably be encapsulated in the job_boss gem):
67
+ From your Rails code or in a console:
50
68
 
51
- require 'job_boss/boss'
69
+ require 'job_boss'
52
70
  jobs = (0..1000).collect do |i|
53
- JobBoss::Boss.queue.math.is_prime?(i)
71
+ Boss.queue.math.is_prime?(i)
54
72
  end
55
73
 
56
- JobBoss::Job.wait_for_jobs(jobs) # Will sleep until the jobs are all complete
74
+ Or:
75
+
76
+ jobs = []
77
+ Article.select('id').find_in_batches(:batch_size => 10) do |articles|
78
+ jobs << Boss.queue.article.refresh_cache(articles.collect(&:id))
79
+ end
80
+
81
+ job_boss also makes it easy to wait for the jobs to be done and to collect the results into a hash:
82
+
83
+ Job.wait_for_jobs(jobs) # Will sleep until the jobs are all complete
84
+
85
+ Job.result_hash(jobs) # => {[0]=>false, [1]=>false, [2]=>true, [3]=>true, [4]=>false, ... }
86
+
87
+ For performance, it is recommended that you keep your jobs table clean scheduling execution of the `delete_jobs_before` command on the Job model, which will clean all jobs completed before the specified time:
57
88
 
58
- JobBoss::Job.result_hash(jobs) # => {[0]=>false, [1]=>false, [2]=>true, [3]=>true, [4]=>false, ... }
89
+ Job.delete_jobs_before(2.days.ago)
59
90
 
60
91
  Features:
61
92
 
@@ -63,4 +94,5 @@ Features:
63
94
  * Call the `mark_for_redo` method on a job to have it processed again. This is automatically run for all currently running jobs in the event that the boss has been told to stop
64
95
  * If a job throws an exception, it will be caught and recorded. Call the `error` method on a job to find out what the error was
65
96
  * Find out how long the job took by calling the `time_taken` method on a job
66
- * The job boss dispatches "employees" to work on jobs. Viewing the processes, the process name is changed to reflect which jobs employees are working on for easy tracing (e.g. `[job_boss] employee (job #4)`)
97
+ * The job boss dispatches "employees" to work on jobs. Viewing the processes, the process name is changed to reflect which jobs employees are working on for easy tracing (e.g. `[job_boss employee] job #4 math#is_prime?(4)`)
98
+
data/bin/job_boss CHANGED
@@ -15,8 +15,6 @@ daemons_options = {
15
15
  Daemons.run_proc('job_boss', daemons_options) do
16
16
  Dir.chdir(working_dir)
17
17
 
18
- require 'config/environment' if File.exist?('config/environment.rb')
19
-
20
18
  $: << File.expand_path('../../lib', __FILE__)
21
19
  require 'job_boss/boss'
22
20
 
@@ -24,6 +22,10 @@ Daemons.run_proc('job_boss', daemons_options) do
24
22
 
25
23
  JobBoss::Boss.config.parse_args(app_options, :working_dir => working_dir)
26
24
 
25
+ Dir.chdir(JobBoss::Boss.config.application_root)
26
+
27
+ require 'config/environment' if File.exist?('config/environment.rb')
28
+
27
29
  boss = JobBoss::Boss.new
28
30
 
29
31
  boss.start
@@ -104,6 +104,10 @@
104
104
  <h3 class="section-header">Files</h3>
105
105
  <ul>
106
106
 
107
+ <li class="file"><a href="../Gemfile.html">Gemfile</a></li>
108
+
109
+ <li class="file"><a href="../MIT-LICENSE.html">MIT-LICENSE</a></li>
110
+
107
111
  <li class="file"><a href="../Rakefile.html">Rakefile</a></li>
108
112
 
109
113
  </ul>
@@ -145,6 +149,8 @@
145
149
 
146
150
  <li><a href="../MathJobs.html">MathJobs</a></li>
147
151
 
152
+ <li><a href="../Penguin.html">Penguin</a></li>
153
+
148
154
  <li><a href="../SleepJobs.html">SleepJobs</a></li>
149
155
 
150
156
  <li><a href="../StringJobs.html">StringJobs</a></li>
@@ -182,7 +188,7 @@
182
188
  <div class="method-heading">
183
189
 
184
190
  <span class="method-name">assert_pid_not_running</span><span
185
- class="method-args">(pid)</span>
191
+ class="method-args">(pid, message="")</span>
186
192
  <span class="method-click-advice">click to toggle source</span>
187
193
 
188
194
  </div>
@@ -196,12 +202,18 @@
196
202
  <div class="method-source-code"
197
203
  id="assert-pid-not-running-source">
198
204
  <pre>
199
- <span class="ruby-comment cmt"># File test/test_helper.rb, line 35</span>
200
- 35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_pid_not_running</span>(<span class="ruby-identifier">pid</span>)
201
- 36: <span class="ruby-identifier">assert_raise</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ESRCH</span> <span class="ruby-keyword kw">do</span>
202
- 37: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">pid</span>)
203
- 38: <span class="ruby-keyword kw">end</span>
204
- 39: <span class="ruby-keyword kw">end</span></pre>
205
+ <span class="ruby-comment cmt"># File test/test_helper.rb, line 43</span>
206
+ 43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_pid_not_running</span>(<span class="ruby-identifier">pid</span>, <span class="ruby-identifier">message</span>=<span class="ruby-value str">&quot;&quot;</span>)
207
+ 44: <span class="ruby-identifier">full_message</span> = <span class="ruby-identifier">build_message</span>(<span class="ruby-identifier">message</span>, <span class="ruby-value str">&quot;PID &lt;?&gt; expected to not be running.&quot;</span>, <span class="ruby-identifier">pid</span>)
208
+ 45: <span class="ruby-identifier">assert_block</span>(<span class="ruby-identifier">full_message</span>) <span class="ruby-keyword kw">do</span>
209
+ 46: <span class="ruby-keyword kw">begin</span>
210
+ 47: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">pid</span>.<span class="ruby-identifier">to_i</span>)
211
+ 48: <span class="ruby-keyword kw">false</span>
212
+ 49: <span class="ruby-keyword kw">rescue</span>
213
+ 50: <span class="ruby-keyword kw">true</span>
214
+ 51: <span class="ruby-keyword kw">end</span>
215
+ 52: <span class="ruby-keyword kw">end</span>
216
+ 53: <span class="ruby-keyword kw">end</span></pre>
205
217
  </div>
206
218
 
207
219
  </div>
@@ -218,7 +230,7 @@
218
230
  <div class="method-heading">
219
231
 
220
232
  <span class="method-name">assert_pid_running</span><span
221
- class="method-args">(pid)</span>
233
+ class="method-args">(pid, message="")</span>
222
234
  <span class="method-click-advice">click to toggle source</span>
223
235
 
224
236
  </div>
@@ -232,12 +244,18 @@
232
244
  <div class="method-source-code"
233
245
  id="assert-pid-running-source">
234
246
  <pre>
235
- <span class="ruby-comment cmt"># File test/test_helper.rb, line 29</span>
236
- 29: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_pid_running</span>(<span class="ruby-identifier">pid</span>)
237
- 30: <span class="ruby-identifier">assert_nothing_raised</span> <span class="ruby-keyword kw">do</span>
238
- 31: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">pid</span>)
239
- 32: <span class="ruby-keyword kw">end</span>
240
- 33: <span class="ruby-keyword kw">end</span></pre>
247
+ <span class="ruby-comment cmt"># File test/test_helper.rb, line 31</span>
248
+ 31: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_pid_running</span>(<span class="ruby-identifier">pid</span>, <span class="ruby-identifier">message</span>=<span class="ruby-value str">&quot;&quot;</span>)
249
+ 32: <span class="ruby-identifier">full_message</span> = <span class="ruby-identifier">build_message</span>(<span class="ruby-identifier">message</span>, <span class="ruby-value str">&quot;PID &lt;?&gt; expected to be running.&quot;</span>, <span class="ruby-identifier">pid</span>)
250
+ 33: <span class="ruby-identifier">assert_block</span>(<span class="ruby-identifier">full_message</span>) <span class="ruby-keyword kw">do</span>
251
+ 34: <span class="ruby-keyword kw">begin</span>
252
+ 35: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">pid</span>.<span class="ruby-identifier">to_i</span>)
253
+ 36: <span class="ruby-keyword kw">true</span>
254
+ 37: <span class="ruby-keyword kw">rescue</span>
255
+ 38: <span class="ruby-keyword kw">false</span>
256
+ 39: <span class="ruby-keyword kw">end</span>
257
+ 40: <span class="ruby-keyword kw">end</span>
258
+ 41: <span class="ruby-keyword kw">end</span></pre>
241
259
  </div>
242
260
 
243
261
  </div>
@@ -268,11 +286,11 @@
268
286
  <div class="method-source-code"
269
287
  id="clean-app-environment-source">
270
288
  <pre>
271
- <span class="ruby-comment cmt"># File test/test_helper.rb, line 24</span>
272
- 24: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clean_app_environment</span>
273
- 25: <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-ivar">@db_path</span>, <span class="ruby-value str">'*'</span>)).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">unlink</span>(<span class="ruby-identifier">path</span>) }
274
- 26: <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-ivar">@app_root_path</span>, <span class="ruby-value str">'log'</span>, <span class="ruby-value str">'*'</span>)).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">unlink</span>(<span class="ruby-identifier">path</span>) }
275
- 27: <span class="ruby-keyword kw">end</span></pre>
289
+ <span class="ruby-comment cmt"># File test/test_helper.rb, line 26</span>
290
+ 26: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clean_app_environment</span>
291
+ 27: <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-ivar">@db_path</span>, <span class="ruby-value str">'*'</span>)).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">unlink</span>(<span class="ruby-identifier">path</span>) }
292
+ 28: <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-ivar">@app_root_path</span>, <span class="ruby-value str">'log'</span>, <span class="ruby-value str">'*'</span>)).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">unlink</span>(<span class="ruby-identifier">path</span>) }
293
+ 29: <span class="ruby-keyword kw">end</span></pre>
276
294
  </div>
277
295
 
278
296
  </div>
@@ -303,10 +321,10 @@
303
321
  <div class="method-source-code"
304
322
  id="get-pid-from-startup-source">
305
323
  <pre>
306
- <span class="ruby-comment cmt"># File test/test_helper.rb, line 59</span>
307
- 59: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_pid_from_startup</span>(<span class="ruby-identifier">output</span>)
308
- 60: <span class="ruby-identifier">output</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/job_boss: process with pid (\d+) started./</span>)[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>
309
- 61: <span class="ruby-keyword kw">end</span></pre>
324
+ <span class="ruby-comment cmt"># File test/test_helper.rb, line 73</span>
325
+ 73: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_pid_from_startup</span>(<span class="ruby-identifier">output</span>)
326
+ 74: <span class="ruby-identifier">output</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/job_boss: process with pid (\d+) started./</span>)[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>
327
+ 75: <span class="ruby-keyword kw">end</span></pre>
310
328
  </div>
311
329
 
312
330
  </div>
@@ -337,20 +355,20 @@
337
355
  <div class="method-source-code"
338
356
  id="restart-daemon-source">
339
357
  <pre>
340
- <span class="ruby-comment cmt"># File test/test_helper.rb, line 88</span>
341
- 88: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restart_daemon</span>
342
- 89: <span class="ruby-identifier">assert_pid_running</span>(<span class="ruby-ivar">@daemon_pid</span>)
343
- 90:
344
- 91: <span class="ruby-identifier">output</span> = <span class="ruby-value">`bin/job_boss restart`</span>
345
- 92:
346
- 93: <span class="ruby-comment cmt"># Give the daemon a bit of time to stop</span>
347
- 94: <span class="ruby-identifier">sleep</span>(<span class="ruby-value">0.5</span>)
348
- 95: <span class="ruby-identifier">assert_pid_not_running</span>(<span class="ruby-ivar">@daemon_pid</span>)
349
- 96:
350
- 97: <span class="ruby-ivar">@daemon_pid</span> = <span class="ruby-identifier">get_pid_from_startup</span>(<span class="ruby-identifier">output</span>)
351
- 98:
352
- 99: <span class="ruby-identifier">assert_pid_running</span>(<span class="ruby-ivar">@daemon_pid</span>)
353
- 100: <span class="ruby-keyword kw">end</span></pre>
358
+ <span class="ruby-comment cmt"># File test/test_helper.rb, line 102</span>
359
+ 102: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restart_daemon</span>
360
+ 103: <span class="ruby-identifier">assert_pid_running</span>(<span class="ruby-ivar">@daemon_pid</span>)
361
+ 104:
362
+ 105: <span class="ruby-identifier">output</span> = <span class="ruby-node">`#{@job_boss_bin_path} restart`</span>
363
+ 106:
364
+ 107: <span class="ruby-comment cmt"># Give the daemon a bit of time to stop</span>
365
+ 108: <span class="ruby-comment cmt"># sleep(0.5)</span>
366
+ 109: <span class="ruby-identifier">assert_pid_not_running</span>(<span class="ruby-ivar">@daemon_pid</span>)
367
+ 110:
368
+ 111: <span class="ruby-ivar">@daemon_pid</span> = <span class="ruby-identifier">get_pid_from_startup</span>(<span class="ruby-identifier">output</span>)
369
+ 112:
370
+ 113: <span class="ruby-identifier">assert_pid_running</span>(<span class="ruby-ivar">@daemon_pid</span>)
371
+ 114: <span class="ruby-keyword kw">end</span></pre>
354
372
  </div>
355
373
 
356
374
  </div>
@@ -381,13 +399,14 @@
381
399
  <div class="method-source-code"
382
400
  id="setup-paths-source">
383
401
  <pre>
384
- <span class="ruby-comment cmt"># File test/test_helper.rb, line 17</span>
385
- 17: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">setup_paths</span>
386
- 18: <span class="ruby-ivar">@app_root_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">'test'</span>, <span class="ruby-value str">'app_root'</span>)
387
- 19: <span class="ruby-ivar">@db_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@app_root_path</span>, <span class="ruby-value str">'db'</span>)
388
- 20: <span class="ruby-ivar">@log_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@app_root_path</span>, <span class="ruby-value str">'log'</span>, <span class="ruby-value str">'job_boss.log'</span>)
389
- 21: <span class="ruby-ivar">@db_yaml_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@app_root_path</span>, <span class="ruby-value str">'config'</span>, <span class="ruby-value str">'database.yml'</span>)
390
- 22: <span class="ruby-keyword kw">end</span></pre>
402
+ <span class="ruby-comment cmt"># File test/test_helper.rb, line 18</span>
403
+ 18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">setup_paths</span>
404
+ 19: <span class="ruby-ivar">@job_boss_bin_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-value str">'../../bin/job_boss'</span>, <span class="ruby-keyword kw">__FILE__</span>)
405
+ 20: <span class="ruby-ivar">@app_root_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-value str">'../app_root'</span>, <span class="ruby-keyword kw">__FILE__</span>)
406
+ 21: <span class="ruby-ivar">@db_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@app_root_path</span>, <span class="ruby-value str">'db'</span>)
407
+ 22: <span class="ruby-ivar">@log_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@app_root_path</span>, <span class="ruby-value str">'log'</span>, <span class="ruby-value str">'job_boss.log'</span>)
408
+ 23: <span class="ruby-ivar">@db_yaml_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@app_root_path</span>, <span class="ruby-value str">'config'</span>, <span class="ruby-value str">'database.yml'</span>)
409
+ 24: <span class="ruby-keyword kw">end</span></pre>
391
410
  </div>
392
411
 
393
412
  </div>
@@ -418,24 +437,24 @@
418
437
  <div class="method-source-code"
419
438
  id="start-daemon-source">
420
439
  <pre>
421
- <span class="ruby-comment cmt"># File test/test_helper.rb, line 41</span>
422
- 41: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start_daemon</span>(<span class="ruby-identifier">options</span>)
423
- 42: <span class="ruby-identifier">clean_app_environment</span>
424
- 43:
425
- 44: <span class="ruby-identifier">stop_daemon</span>
426
- 45:
427
- 46: <span class="ruby-identifier">option_string</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">collect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
428
- 47: <span class="ruby-value str">'--'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'_'</span>, <span class="ruby-value str">'-'</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot; &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>
429
- 48: <span class="ruby-keyword kw">end</span>
430
- 49:
431
- 50: <span class="ruby-identifier">output</span> = <span class="ruby-node">`bin/job_boss start -- #{option_string.join(' ')}`</span>
432
- 51:
433
- 52: <span class="ruby-ivar">@daemon_pid</span> = <span class="ruby-identifier">get_pid_from_startup</span>(<span class="ruby-identifier">output</span>)
434
- 53:
435
- 54: <span class="ruby-identifier">assert_pid_running</span>(<span class="ruby-ivar">@daemon_pid</span>)
436
- 55:
437
- 56: <span class="ruby-ivar">@daemon_pid</span>
438
- 57: <span class="ruby-keyword kw">end</span></pre>
440
+ <span class="ruby-comment cmt"># File test/test_helper.rb, line 55</span>
441
+ 55: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start_daemon</span>(<span class="ruby-identifier">options</span>)
442
+ 56: <span class="ruby-identifier">clean_app_environment</span>
443
+ 57:
444
+ 58: <span class="ruby-identifier">stop_daemon</span>
445
+ 59:
446
+ 60: <span class="ruby-identifier">option_string</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">collect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
447
+ 61: <span class="ruby-value str">'--'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'_'</span>, <span class="ruby-value str">'-'</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot; &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>
448
+ 62: <span class="ruby-keyword kw">end</span>
449
+ 63:
450
+ 64: <span class="ruby-identifier">output</span> = <span class="ruby-node">`#{@job_boss_bin_path} start -- #{option_string.join(' ')}`</span>
451
+ 65:
452
+ 66: <span class="ruby-ivar">@daemon_pid</span> = <span class="ruby-identifier">get_pid_from_startup</span>(<span class="ruby-identifier">output</span>)
453
+ 67:
454
+ 68: <span class="ruby-identifier">assert_pid_running</span>(<span class="ruby-ivar">@daemon_pid</span>)
455
+ 69:
456
+ 70: <span class="ruby-ivar">@daemon_pid</span>
457
+ 71: <span class="ruby-keyword kw">end</span></pre>
439
458
  </div>
440
459
 
441
460
  </div>
@@ -466,14 +485,14 @@
466
485
  <div class="method-source-code"
467
486
  id="stop-daemon-source">
468
487
  <pre>
469
- <span class="ruby-comment cmt"># File test/test_helper.rb, line 80</span>
470
- 80: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop_daemon</span>
471
- 81: <span class="ruby-value">`bin/job_boss stop`</span>
472
- 82:
473
- 83: <span class="ruby-comment cmt"># Give the daemon a bit of time to stop</span>
474
- 84: <span class="ruby-identifier">sleep</span>(<span class="ruby-value">0.5</span>)
475
- 85: <span class="ruby-identifier">assert_pid_not_running</span>(<span class="ruby-ivar">@daemon_pid</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@daemon_pid</span>
476
- 86: <span class="ruby-keyword kw">end</span></pre>
488
+ <span class="ruby-comment cmt"># File test/test_helper.rb, line 94</span>
489
+ 94: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop_daemon</span>
490
+ 95: <span class="ruby-node">`#{@job_boss_bin_path} stop`</span>
491
+ 96:
492
+ 97: <span class="ruby-comment cmt"># Give the daemon a bit of time to stop</span>
493
+ 98: <span class="ruby-comment cmt"># sleep(0.5)</span>
494
+ 99: <span class="ruby-identifier">assert_pid_not_running</span>(<span class="ruby-ivar">@daemon_pid</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@daemon_pid</span>
495
+ 100: <span class="ruby-keyword kw">end</span></pre>
477
496
  </div>
478
497
 
479
498
  </div>
@@ -504,16 +523,16 @@
504
523
  <div class="method-source-code"
505
524
  id="wait-for-file-source">
506
525
  <pre>
507
- <span class="ruby-comment cmt"># File test/test_helper.rb, line 63</span>
508
- 63: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait_for_file</span>(<span class="ruby-identifier">file_path</span>, <span class="ruby-identifier">timeout</span> = <span class="ruby-value">5</span>)
509
- 64: <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
510
- 65: <span class="ruby-keyword kw">until</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">file_path</span>)
511
- 66: <span class="ruby-identifier">sleep</span>(<span class="ruby-value">1</span>)
512
- 67:
513
- 68: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;File failed to appear!&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">timeout</span>
514
- 69: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
515
- 70: <span class="ruby-keyword kw">end</span>
516
- 71: <span class="ruby-keyword kw">end</span></pre>
526
+ <span class="ruby-comment cmt"># File test/test_helper.rb, line 77</span>
527
+ 77: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait_for_file</span>(<span class="ruby-identifier">file_path</span>, <span class="ruby-identifier">timeout</span> = <span class="ruby-value">5</span>)
528
+ 78: <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
529
+ 79: <span class="ruby-keyword kw">until</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">file_path</span>)
530
+ 80: <span class="ruby-identifier">sleep</span>(<span class="ruby-value">1</span>)
531
+ 81:
532
+ 82: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;File failed to appear!&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">timeout</span>
533
+ 83: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
534
+ 84: <span class="ruby-keyword kw">end</span>
535
+ 85: <span class="ruby-keyword kw">end</span></pre>
517
536
  </div>
518
537
 
519
538
  </div>
@@ -544,13 +563,13 @@
544
563
  <div class="method-source-code"
545
564
  id="wait-until-job-assigned-source">
546
565
  <pre>
547
- <span class="ruby-comment cmt"># File test/test_helper.rb, line 73</span>
548
- 73: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait_until_job_assigned</span>(<span class="ruby-identifier">job</span>, <span class="ruby-identifier">wait_interval</span> = <span class="ruby-value">0.5</span>)
549
- 74: <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">job</span>.<span class="ruby-identifier">assigned?</span>
550
- 75: <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">wait_interval</span>)
551
- 76: <span class="ruby-identifier">job</span>.<span class="ruby-identifier">reload</span>
552
- 77: <span class="ruby-keyword kw">end</span>
553
- 78: <span class="ruby-keyword kw">end</span></pre>
566
+ <span class="ruby-comment cmt"># File test/test_helper.rb, line 87</span>
567
+ 87: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait_until_job_assigned</span>(<span class="ruby-identifier">job</span>, <span class="ruby-identifier">wait_interval</span> = <span class="ruby-value">0.5</span>)
568
+ 88: <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">job</span>.<span class="ruby-identifier">assigned?</span>
569
+ 89: <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">wait_interval</span>)
570
+ 90: <span class="ruby-identifier">job</span>.<span class="ruby-identifier">reload</span>
571
+ 91: <span class="ruby-keyword kw">end</span>
572
+ 92: <span class="ruby-keyword kw">end</span></pre>
554
573
  </div>
555
574
 
556
575
  </div>
@@ -76,6 +76,10 @@
76
76
  <h3 class="section-header">Files</h3>
77
77
  <ul>
78
78
 
79
+ <li class="file"><a href="./Gemfile.html">Gemfile</a></li>
80
+
81
+ <li class="file"><a href="./MIT-LICENSE.html">MIT-LICENSE</a></li>
82
+
79
83
  <li class="file"><a href="./Rakefile.html">Rakefile</a></li>
80
84
 
81
85
  </ul>
@@ -117,6 +121,8 @@
117
121
 
118
122
  <li><a href="./MathJobs.html">MathJobs</a></li>
119
123
 
124
+ <li><a href="./Penguin.html">Penguin</a></li>
125
+
120
126
  <li><a href="./SleepJobs.html">SleepJobs</a></li>
121
127
 
122
128
  <li><a href="./StringJobs.html">StringJobs</a></li>
data/doc/CreateJobs.html CHANGED
@@ -88,6 +88,10 @@
88
88
  <h3 class="section-header">Files</h3>
89
89
  <ul>
90
90
 
91
+ <li class="file"><a href="./Gemfile.html">Gemfile</a></li>
92
+
93
+ <li class="file"><a href="./MIT-LICENSE.html">MIT-LICENSE</a></li>
94
+
91
95
  <li class="file"><a href="./Rakefile.html">Rakefile</a></li>
92
96
 
93
97
  </ul>
@@ -129,6 +133,8 @@
129
133
 
130
134
  <li><a href="./MathJobs.html">MathJobs</a></li>
131
135
 
136
+ <li><a href="./Penguin.html">Penguin</a></li>
137
+
132
138
  <li><a href="./SleepJobs.html">SleepJobs</a></li>
133
139
 
134
140
  <li><a href="./StringJobs.html">StringJobs</a></li>
@@ -180,10 +186,10 @@
180
186
  <div class="method-source-code"
181
187
  id="down-source">
182
188
  <pre>
183
- <span class="ruby-comment cmt"># File lib/migrate.rb, line 26</span>
184
- 26: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">down</span>
185
- 27: <span class="ruby-identifier">drop_table</span> <span class="ruby-value">:jobs</span>
186
- 28: <span class="ruby-keyword kw">end</span></pre>
189
+ <span class="ruby-comment cmt"># File lib/migrate.rb, line 32</span>
190
+ 32: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">down</span>
191
+ 33: <span class="ruby-identifier">drop_table</span> <span class="ruby-value">:jobs</span>
192
+ 34: <span class="ruby-keyword kw">end</span></pre>
187
193
  </div>
188
194
 
189
195
  </div>
@@ -237,7 +243,13 @@
237
243
  21:
238
244
  22: <span class="ruby-identifier">add_index</span> <span class="ruby-value">:jobs</span>, <span class="ruby-value">:path</span>
239
245
  23: <span class="ruby-identifier">add_index</span> <span class="ruby-value">:jobs</span>, <span class="ruby-value">:status</span>
240
- 24: <span class="ruby-keyword kw">end</span></pre>
246
+ 24:
247
+ 25: <span class="ruby-identifier">postgres</span> = (<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">adapter_name</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'PostgreSQL'</span>)
248
+ 26:
249
+ 27: [<span class="ruby-value str">'started_at'</span>, <span class="ruby-value str">'cancelled_at'</span>, <span class="ruby-value str">'completed_at'</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">field</span><span class="ruby-operator">|</span>
250
+ 28: <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;CREATE INDEX IF NOT EXISTS jobs_#{field}_is_null ON jobs (#{field})&quot;</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">postgres</span> <span class="ruby-operator">?</span> <span class="ruby-node">&quot; WHERE #{field} IS NULL&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">''</span>)
251
+ 29: <span class="ruby-keyword kw">end</span>
252
+ 30: <span class="ruby-keyword kw">end</span></pre>
241
253
  </div>
242
254
 
243
255
  </div>
data/doc/DaemonTest.html CHANGED
@@ -80,6 +80,10 @@
80
80
  <h3 class="section-header">Files</h3>
81
81
  <ul>
82
82
 
83
+ <li class="file"><a href="./Gemfile.html">Gemfile</a></li>
84
+
85
+ <li class="file"><a href="./MIT-LICENSE.html">MIT-LICENSE</a></li>
86
+
83
87
  <li class="file"><a href="./Rakefile.html">Rakefile</a></li>
84
88
 
85
89
  </ul>
@@ -121,6 +125,8 @@
121
125
 
122
126
  <li><a href="./MathJobs.html">MathJobs</a></li>
123
127
 
128
+ <li><a href="./Penguin.html">Penguin</a></li>
129
+
124
130
  <li><a href="./SleepJobs.html">SleepJobs</a></li>
125
131
 
126
132
  <li><a href="./StringJobs.html">StringJobs</a></li>