job_boss 0.5.5 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -309,50 +309,50 @@
309
309
  <div class="method-source-code"
310
310
  id="parse-args-source">
311
311
  <pre>
312
- <span class="ruby-comment cmt"># File lib/job_boss/config.rb, line 5</span>
313
- 5: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_args</span>(<span class="ruby-identifier">argv</span>, <span class="ruby-identifier">options</span> = {})
314
- 6: <span class="ruby-ivar">@application_root</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:working_dir</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">pwd</span>)
315
- 7: <span class="ruby-ivar">@database_yaml_path</span> = <span class="ruby-value str">'config/database.yml'</span>
316
- 8: <span class="ruby-ivar">@log_path</span> = <span class="ruby-value str">'log/job_boss.log'</span>
317
- 9: <span class="ruby-ivar">@jobs_path</span> = <span class="ruby-value str">'app/jobs'</span>
318
- 10: <span class="ruby-ivar">@sleep_interval</span> = <span class="ruby-value">0.5</span>
319
- 11: <span class="ruby-ivar">@employee_limit</span> = <span class="ruby-value">4</span>
320
- 12: <span class="ruby-ivar">@environment</span> = <span class="ruby-value str">'development'</span>
321
- 13:
322
- 14: <span class="ruby-identifier">require</span> <span class="ruby-value str">'optparse'</span>
312
+ <span class="ruby-comment cmt"># File lib/job_boss/config.rb, line 7</span>
313
+ 7: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_args</span>(<span class="ruby-identifier">argv</span>, <span class="ruby-identifier">options</span> = {})
314
+ 8: <span class="ruby-ivar">@application_root</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_APPLICATION_ROOT'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:working_dir</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">pwd</span>)
315
+ 9: <span class="ruby-ivar">@database_yaml_path</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_DATABASE_YAML_PATH'</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'config/database.yml'</span>
316
+ 10: <span class="ruby-ivar">@log_path</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_LOG_PATH'</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'log/job_boss.log'</span>
317
+ 11: <span class="ruby-ivar">@jobs_path</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_JOBS_PATH'</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'app/jobs'</span>
318
+ 12: <span class="ruby-ivar">@sleep_interval</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_SLEEP_INTERVAL'</span>].<span class="ruby-identifier">blank?</span> <span class="ruby-operator">?</span> <span class="ruby-value">0.5</span> <span class="ruby-operator">:</span> <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_SLEEP_INTERVAL'</span>].<span class="ruby-identifier">to_f</span>
319
+ 13: <span class="ruby-ivar">@employee_limit</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_EMPLOYEE_LIMIT'</span>].<span class="ruby-identifier">blank?</span> <span class="ruby-operator">?</span> <span class="ruby-value">4</span> <span class="ruby-operator">:</span> <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_EMPLOYEE_LIMIT'</span>].<span class="ruby-identifier">to_i</span>
320
+ 14: <span class="ruby-ivar">@environment</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'JB_ENVIRONMENT'</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'development'</span>
323
321
  15:
324
- 16: <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
325
- 17: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-value str">&quot;Usage: job_boss [start|stop|restart|run|zap] [-- &lt;options&gt;]&quot;</span>
326
- 18:
327
- 19: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-r&quot;</span>, <span class="ruby-value str">&quot;--application-root PATH&quot;</span>, <span class="ruby-value str">&quot;Path for the application root upon which other paths depend (defaults to .)&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
328
- 20: <span class="ruby-ivar">@application_root</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">path</span>)
329
- 21: <span class="ruby-keyword kw">end</span>
330
- 22:
331
- 23: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-d&quot;</span>, <span class="ruby-value str">&quot;--database-yaml PATH&quot;</span>, <span class="ruby-node">&quot;Path for database YAML (defaults to &lt;application-root&gt;/#{@database_yaml_path})&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
332
- 24: <span class="ruby-ivar">@database_yaml_path</span> = <span class="ruby-identifier">path</span>
333
- 25: <span class="ruby-keyword kw">end</span>
334
- 26:
335
- 27: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-l&quot;</span>, <span class="ruby-value str">&quot;--log-path PATH&quot;</span>, <span class="ruby-node">&quot;Path for log file (defaults to &lt;application-root&gt;/#{@log_path})&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
336
- 28: <span class="ruby-ivar">@log_path</span> = <span class="ruby-identifier">path</span>
337
- 29: <span class="ruby-keyword kw">end</span>
338
- 30:
339
- 31: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-j&quot;</span>, <span class="ruby-value str">&quot;--jobs-path PATH&quot;</span>, <span class="ruby-node">&quot;Path to folder with job classes (defaults to &lt;application-root&gt;/#{@jobs_path})&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
340
- 32: <span class="ruby-ivar">@jobs_path</span> = <span class="ruby-identifier">path</span>
341
- 33: <span class="ruby-keyword kw">end</span>
342
- 34:
343
- 35: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-e&quot;</span>, <span class="ruby-value str">&quot;--environment ENV&quot;</span>, <span class="ruby-node">&quot;Environment to use in database YAML file (defaults to '#{@environment}')&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">env</span><span class="ruby-operator">|</span>
344
- 36: <span class="ruby-ivar">@environment</span> = <span class="ruby-identifier">env</span>
345
- 37: <span class="ruby-keyword kw">end</span>
346
- 38:
347
- 39: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-s&quot;</span>, <span class="ruby-value str">&quot;--sleep-interval INTERVAL&quot;</span>, <span class="ruby-constant">Integer</span>, <span class="ruby-node">&quot;Number of seconds for the boss to sleep between checks of the queue (default #{@sleep_interval})&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">interval</span><span class="ruby-operator">|</span>
348
- 40: <span class="ruby-ivar">@sleep_interval</span> = <span class="ruby-identifier">interval</span>
349
- 41: <span class="ruby-keyword kw">end</span>
350
- 42:
351
- 43: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-c&quot;</span>, <span class="ruby-value str">&quot;--employee-limit LIMIT&quot;</span>, <span class="ruby-constant">Integer</span>, <span class="ruby-value str">&quot;Maximum number of employees (default 4)&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">limit</span><span class="ruby-operator">|</span>
352
- 44: <span class="ruby-ivar">@employee_limit</span> = <span class="ruby-identifier">limit</span>
353
- 45: <span class="ruby-keyword kw">end</span>
354
- 46: <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">argv</span>)
355
- 47: <span class="ruby-keyword kw">end</span></pre>
322
+ 16: <span class="ruby-identifier">require</span> <span class="ruby-value str">'optparse'</span>
323
+ 17:
324
+ 18: <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
325
+ 19: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-value str">&quot;Usage: job_boss [start|stop|restart|run|zap] [-- &lt;options&gt;]&quot;</span>
326
+ 20:
327
+ 21: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-r&quot;</span>, <span class="ruby-value str">&quot;--application-root PATH&quot;</span>, <span class="ruby-value str">&quot;Path for the application root upon which other paths depend (defaults to .) Environment variable: JB_APPLICATION_ROOT&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
328
+ 22: <span class="ruby-ivar">@application_root</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">path</span>)
329
+ 23: <span class="ruby-keyword kw">end</span>
330
+ 24:
331
+ 25: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-d&quot;</span>, <span class="ruby-value str">&quot;--database-yaml PATH&quot;</span>, <span class="ruby-node">&quot;Path for database YAML (defaults to &lt;application-root&gt;/#{@database_yaml_path}) Environment variable: JB_DATABASE_YAML_PATH&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
332
+ 26: <span class="ruby-ivar">@database_yaml_path</span> = <span class="ruby-identifier">path</span>
333
+ 27: <span class="ruby-keyword kw">end</span>
334
+ 28:
335
+ 29: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-l&quot;</span>, <span class="ruby-value str">&quot;--log-path PATH&quot;</span>, <span class="ruby-node">&quot;Path for log file (defaults to &lt;application-root&gt;/#{@log_path}) Environment variable: JB_LOG_PATH&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
336
+ 30: <span class="ruby-ivar">@log_path</span> = <span class="ruby-identifier">path</span>
337
+ 31: <span class="ruby-keyword kw">end</span>
338
+ 32:
339
+ 33: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-j&quot;</span>, <span class="ruby-value str">&quot;--jobs-path PATH&quot;</span>, <span class="ruby-node">&quot;Path to folder with job classes (defaults to &lt;application-root&gt;/#{@jobs_path}) Environment variable: JB_JOBS_PATH&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
340
+ 34: <span class="ruby-ivar">@jobs_path</span> = <span class="ruby-identifier">path</span>
341
+ 35: <span class="ruby-keyword kw">end</span>
342
+ 36:
343
+ 37: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-e&quot;</span>, <span class="ruby-value str">&quot;--environment ENV&quot;</span>, <span class="ruby-node">&quot;Environment to use in database YAML file (defaults to '#{@environment}') Environment variable: JB_ENVIRONMENT&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">env</span><span class="ruby-operator">|</span>
344
+ 38: <span class="ruby-ivar">@environment</span> = <span class="ruby-identifier">env</span>
345
+ 39: <span class="ruby-keyword kw">end</span>
346
+ 40:
347
+ 41: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-s&quot;</span>, <span class="ruby-value str">&quot;--sleep-interval INTERVAL&quot;</span>, <span class="ruby-constant">Integer</span>, <span class="ruby-node">&quot;Number of seconds for the boss to sleep between checks of the queue (default #{@sleep_interval}) Environment variable: JB_SLEEP_INTERVAL&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">interval</span><span class="ruby-operator">|</span>
348
+ 42: <span class="ruby-ivar">@sleep_interval</span> = <span class="ruby-identifier">interval</span>
349
+ 43: <span class="ruby-keyword kw">end</span>
350
+ 44:
351
+ 45: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-c&quot;</span>, <span class="ruby-value str">&quot;--employee-limit LIMIT&quot;</span>, <span class="ruby-constant">Integer</span>, <span class="ruby-value str">&quot;Maximum number of employees (default 4) Environment variable: JB_EMPLOYEE_LIMIT&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">limit</span><span class="ruby-operator">|</span>
352
+ 46: <span class="ruby-ivar">@employee_limit</span> = <span class="ruby-identifier">limit</span>
353
+ 47: <span class="ruby-keyword kw">end</span>
354
+ 48: <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">argv</span>)
355
+ 49: <span class="ruby-keyword kw">end</span></pre>
356
356
  </div>
357
357
 
358
358
  </div>
data/doc/JobBoss/Job.html CHANGED
@@ -586,7 +586,7 @@ Is the job complete?
586
586
  <div class="method-heading">
587
587
 
588
588
  <span class="method-name">dispatch</span><span
589
- class="method-args">()</span>
589
+ class="method-args">(boss)</span>
590
590
  <span class="method-click-advice">click to toggle source</span>
591
591
 
592
592
  </div>
@@ -603,9 +603,9 @@ Method used by the boss to dispatch an employee
603
603
  id="dispatch-source">
604
604
  <pre>
605
605
  <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 15</span>
606
- 15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dispatch</span>
606
+ 15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dispatch</span>(<span class="ruby-identifier">boss</span>)
607
607
  16: <span class="ruby-identifier">mark_as_started</span>
608
- 17: <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Dispatching Job ##{self.id}&quot;</span>
608
+ 17: <span class="ruby-identifier">boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Dispatching Job ##{self.id}&quot;</span>
609
609
  18:
610
610
  19: <span class="ruby-identifier">pid</span> = <span class="ruby-identifier">fork</span> <span class="ruby-keyword kw">do</span>
611
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>
@@ -620,7 +620,7 @@ Method used by the boss to dispatch an employee
620
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
621
  30: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">exception</span>
622
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">&quot;Error running job ##{self.id}!&quot;</span>
623
+ 32: <span class="ruby-identifier">boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span> <span class="ruby-node">&quot;Error running job ##{self.id}!&quot;</span>
624
624
  33: <span class="ruby-keyword kw">ensure</span>
625
625
  34: <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">mark_as_completed</span>
626
626
  35: <span class="ruby-identifier">sleep</span>(<span class="ruby-value">1</span>)
@@ -187,45 +187,46 @@
187
187
  <span class="ruby-comment cmt"># File lib/job_boss/queuer.rb, line 3</span>
188
188
  3: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">method_id</span>, *<span class="ruby-identifier">args</span>)
189
189
  4: <span class="ruby-identifier">require</span> <span class="ruby-value str">'active_support'</span>
190
- 5:
191
- 6: <span class="ruby-identifier">method_name</span> = <span class="ruby-identifier">method_id</span>.<span class="ruby-identifier">id2name</span>
192
- 7:
193
- 8: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@class</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@controller</span>
194
- 9: <span class="ruby-comment cmt"># In here, we've already figured out the class, so assume the method_missing call is to the method</span>
195
- 10:
196
- 11: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@class</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">method_name</span>)
197
- 12: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/job'</span>
198
- 13: <span class="ruby-identifier">path</span> = <span class="ruby-node">&quot;#{@controller}##{method_name}&quot;</span>
199
- 14:
200
- 15: <span class="ruby-ivar">@class</span> = <span class="ruby-keyword kw">nil</span>
201
- 16: <span class="ruby-ivar">@controller</span> = <span class="ruby-keyword kw">nil</span>
202
- 17:
203
- 18: <span class="ruby-constant">Job</span>.<span class="ruby-identifier">create</span>(<span class="ruby-value">:path</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">path</span>,
204
- 19: <span class="ruby-value">:args</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>)
205
- 20: <span class="ruby-keyword kw">else</span>
206
- 21: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Invalid action&quot;</span>
207
- 22: <span class="ruby-keyword kw">end</span>
208
- 23: <span class="ruby-keyword kw">else</span>
209
- 24: <span class="ruby-comment cmt"># Check to see if there's a class</span>
210
- 25: <span class="ruby-keyword kw">begin</span>
211
- 26: <span class="ruby-comment cmt"># If we find a class that ends in &quot;Jobs&quot;, we instanciate it and call an instance method</span>
212
- 27: <span class="ruby-ivar">@class</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-node">&quot;#{method_name.classify}Jobs&quot;</span>).<span class="ruby-identifier">new</span>
213
- 28:
214
- 29: <span class="ruby-ivar">@controller</span> = <span class="ruby-identifier">method_name</span>
215
- 30: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
216
- 31: <span class="ruby-keyword kw">begin</span>
217
- 32: <span class="ruby-comment cmt"># If we don't find a class that ends in &quot;Jobs&quot;, we're going to call a class method</span>
218
- 33: <span class="ruby-ivar">@class</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-node">&quot;#{method_name.classify}&quot;</span>)
219
- 34:
220
- 35: <span class="ruby-ivar">@controller</span> = <span class="ruby-identifier">method_name</span>
221
- 36: <span class="ruby-keyword kw">rescue</span>
222
- 37: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Invalid controller&quot;</span>
223
- 38: <span class="ruby-keyword kw">end</span>
224
- 39: <span class="ruby-keyword kw">end</span>
225
- 40:
226
- 41: <span class="ruby-keyword kw">self</span>
227
- 42: <span class="ruby-keyword kw">end</span>
228
- 43: <span class="ruby-keyword kw">end</span></pre>
190
+ 5: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/job'</span>
191
+ 6:
192
+ 7: <span class="ruby-identifier">method_name</span> = <span class="ruby-identifier">method_id</span>.<span class="ruby-identifier">id2name</span>
193
+ 8:
194
+ 9: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@class</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@controller</span>
195
+ 10: <span class="ruby-comment cmt"># In here, we've already figured out the class, so assume the method_missing call is to the method</span>
196
+ 11:
197
+ 12: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@class</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">method_name</span>)
198
+ 13: <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/job'</span>
199
+ 14: <span class="ruby-identifier">path</span> = <span class="ruby-node">&quot;#{@controller}##{method_name}&quot;</span>
200
+ 15:
201
+ 16: <span class="ruby-ivar">@class</span> = <span class="ruby-keyword kw">nil</span>
202
+ 17: <span class="ruby-ivar">@controller</span> = <span class="ruby-keyword kw">nil</span>
203
+ 18:
204
+ 19: <span class="ruby-constant">Job</span>.<span class="ruby-identifier">create</span>(<span class="ruby-value">:path</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">path</span>,
205
+ 20: <span class="ruby-value">:args</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>)
206
+ 21: <span class="ruby-keyword kw">else</span>
207
+ 22: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Invalid action&quot;</span>
208
+ 23: <span class="ruby-keyword kw">end</span>
209
+ 24: <span class="ruby-keyword kw">else</span>
210
+ 25: <span class="ruby-comment cmt"># Check to see if there's a class</span>
211
+ 26: <span class="ruby-keyword kw">begin</span>
212
+ 27: <span class="ruby-comment cmt"># If we find a class that ends in &quot;Jobs&quot;, we instanciate it and call an instance method</span>
213
+ 28: <span class="ruby-ivar">@class</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-node">&quot;#{method_name.classify}Jobs&quot;</span>).<span class="ruby-identifier">new</span>
214
+ 29:
215
+ 30: <span class="ruby-ivar">@controller</span> = <span class="ruby-identifier">method_name</span>
216
+ 31: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
217
+ 32: <span class="ruby-keyword kw">begin</span>
218
+ 33: <span class="ruby-comment cmt"># If we don't find a class that ends in &quot;Jobs&quot;, we're going to call a class method</span>
219
+ 34: <span class="ruby-ivar">@class</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-node">&quot;#{method_name.classify}&quot;</span>)
220
+ 35:
221
+ 36: <span class="ruby-ivar">@controller</span> = <span class="ruby-identifier">method_name</span>
222
+ 37: <span class="ruby-keyword kw">rescue</span>
223
+ 38: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Invalid controller&quot;</span>
224
+ 39: <span class="ruby-keyword kw">end</span>
225
+ 40: <span class="ruby-keyword kw">end</span>
226
+ 41:
227
+ 42: <span class="ruby-keyword kw">self</span>
228
+ 43: <span class="ruby-keyword kw">end</span>
229
+ 44: <span class="ruby-keyword kw">end</span></pre>
229
230
  </div>
230
231
 
231
232
  </div>
data/doc/created.rid CHANGED
@@ -1,14 +1,14 @@
1
- Sat, 11 Dec 2010 17:06:33 -0500
1
+ Sun, 12 Dec 2010 13:52:00 -0500
2
2
  ./bin/job_boss Sat, 11 Dec 2010 15:09:03 -0500
3
3
  ./Gemfile Mon, 29 Nov 2010 09:41:29 -0500
4
4
  ./init.rb Fri, 03 Dec 2010 08:33:46 -0500
5
- ./lib/job_boss/boss.rb Sat, 11 Dec 2010 15:16:17 -0500
5
+ ./lib/job_boss/boss.rb Sun, 12 Dec 2010 13:46:34 -0500
6
6
  ./lib/job_boss/capistrano.rb Wed, 24 Nov 2010 14:13:12 -0500
7
- ./lib/job_boss/config.rb Sat, 11 Dec 2010 15:14:56 -0500
8
- ./lib/job_boss/job.rb Sat, 11 Dec 2010 17:04:01 -0500
9
- ./lib/job_boss/queuer.rb Sat, 11 Dec 2010 14:07:12 -0500
7
+ ./lib/job_boss/config.rb Sun, 12 Dec 2010 13:50:39 -0500
8
+ ./lib/job_boss/job.rb Sun, 12 Dec 2010 13:45:13 -0500
9
+ ./lib/job_boss/queuer.rb Sun, 12 Dec 2010 13:42:58 -0500
10
10
  ./lib/job_boss.rb Fri, 03 Dec 2010 08:55:47 -0500
11
- ./lib/migrate.rb Mon, 06 Dec 2010 20:40:41 -0500
11
+ ./lib/migrate.rb Sun, 12 Dec 2010 13:46:41 -0500
12
12
  ./MIT-LICENSE Fri, 03 Dec 2010 08:38:44 -0500
13
13
  ./Rakefile Sat, 11 Dec 2010 17:05:22 -0500
14
14
  ./test/app_root/app/jobs/math_jobs.rb Sun, 28 Nov 2010 10:56:16 -0500
@@ -16,6 +16,6 @@ Sat, 11 Dec 2010 17:06:33 -0500
16
16
  ./test/app_root/app/jobs/string_jobs.rb Sun, 28 Nov 2010 20:04:58 -0500
17
17
  ./test/app_root/app/models/penguin.rb Sat, 11 Dec 2010 14:25:33 -0500
18
18
  ./test/app_root/config/environment.rb Sat, 11 Dec 2010 16:42:13 -0500
19
- ./test/test_helper.rb Sat, 11 Dec 2010 16:41:41 -0500
20
- ./test/unit/daemon_test.rb Sun, 28 Nov 2010 17:42:32 -0500
21
- ./test/unit/job_test.rb Sat, 11 Dec 2010 17:03:07 -0500
19
+ ./test/test_helper.rb Sun, 12 Dec 2010 11:27:03 -0500
20
+ ./test/unit/daemon_test.rb Sun, 12 Dec 2010 13:36:55 -0500
21
+ ./test/unit/job_test.rb Sun, 12 Dec 2010 13:47:30 -0500
data/doc/index.html CHANGED
@@ -81,8 +81,6 @@
81
81
 
82
82
  <li><a href="CreateJobs.html#method-c-down">::down &mdash; CreateJobs</a></li>
83
83
 
84
- <li><a href="JobBoss/Boss.html#method-c-logger">::logger &mdash; JobBoss::Boss</a></li>
85
-
86
84
  <li><a href="JobBoss/Boss.html#method-c-new">::new &mdash; JobBoss::Boss</a></li>
87
85
 
88
86
  <li><a href="JobBoss/Job.html#method-c-pending_paths">::pending_paths &mdash; JobBoss::Job</a></li>
@@ -121,6 +119,8 @@
121
119
 
122
120
  <li><a href="StringJobs.html#method-i-concatenate">#concatenate &mdash; StringJobs</a></li>
123
121
 
122
+ <li><a href="JobBoss/Boss.html#method-i-config">#config &mdash; JobBoss::Boss</a></li>
123
+
124
124
  <li><a href="JobBoss/Job.html#method-i-dispatch">#dispatch &mdash; JobBoss::Job</a></li>
125
125
 
126
126
  <li><a href="SleepJobs.html#method-i-do_not_never_sleep">#do_not_never_sleep &mdash; SleepJobs</a></li>
@@ -135,6 +135,8 @@
135
135
 
136
136
  <li><a href="JobBoss/Boss.html#method-i-kill_job">#kill_job &mdash; JobBoss::Boss</a></li>
137
137
 
138
+ <li><a href="JobBoss/Boss.html#method-i-logger">#logger &mdash; JobBoss::Boss</a></li>
139
+
138
140
  <li><a href="JobBoss/Job.html#method-i-mark_as_cancelled">#mark_as_cancelled &mdash; JobBoss::Job</a></li>
139
141
 
140
142
  <li><a href="JobBoss/Job.html#method-i-mark_as_completed">#mark_as_completed &mdash; JobBoss::Job</a></li>
@@ -149,8 +151,6 @@
149
151
 
150
152
  <li><a href="JobBoss/Queuer.html#method-i-method_missing">#method_missing &mdash; JobBoss::Queuer</a></li>
151
153
 
152
- <li><a href="JobBoss/Boss.html#method-i-migrate">#migrate &mdash; JobBoss::Boss</a></li>
153
-
154
154
  <li><a href="JobBoss/Config.html#method-i-parse_args">#parse_args &mdash; JobBoss::Config</a></li>
155
155
 
156
156
  <li><a href="JobBoss/Boss.html#method-i-require_job_classes">#require_job_classes &mdash; JobBoss::Boss</a></li>
@@ -24,7 +24,7 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2010-12-11 15:16:17 -0500</dd>
27
+ <dd class="modified-date">2010-12-12 13:46:34 -0500</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
@@ -24,13 +24,15 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2010-12-11 15:14:56 -0500</dd>
27
+ <dd class="modified-date">2010-12-12 13:50:39 -0500</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
31
31
  <dd class="requires">
32
32
  <ul>
33
33
 
34
+ <li>active_support/core_ext/string</li>
35
+
34
36
  <li>optparse</li>
35
37
 
36
38
  </ul>
@@ -24,7 +24,7 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2010-12-11 17:04:01 -0500</dd>
27
+ <dd class="modified-date">2010-12-12 13:45:13 -0500</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
@@ -24,7 +24,7 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2010-12-11 14:07:12 -0500</dd>
27
+ <dd class="modified-date">2010-12-12 13:42:58 -0500</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
@@ -35,6 +35,8 @@
35
35
 
36
36
  <li>job_boss/job</li>
37
37
 
38
+ <li>job_boss/job</li>
39
+
38
40
  </ul>
39
41
  </dd>
40
42
 
@@ -24,7 +24,7 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2010-12-06 20:40:41 -0500</dd>
27
+ <dd class="modified-date">2010-12-12 13:46:41 -0500</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
@@ -24,7 +24,7 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2010-12-11 16:41:41 -0500</dd>
27
+ <dd class="modified-date">2010-12-12 11:27:03 -0500</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
@@ -24,7 +24,7 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2010-11-28 17:42:32 -0500</dd>
27
+ <dd class="modified-date">2010-12-12 13:36:55 -0500</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
@@ -24,7 +24,7 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2010-12-11 17:03:07 -0500</dd>
27
+ <dd class="modified-date">2010-12-12 13:47:30 -0500</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
data/job_boss.gemspec CHANGED
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "job_boss"
7
- s.version = '0.5.5'
7
+ s.version = '0.5.7'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Brian Underwood"]
10
10
  s.email = ["ml+job_boss@semi-sentient.com"]
data/lib/job_boss/boss.rb CHANGED
@@ -2,6 +2,8 @@ require 'active_support'
2
2
 
3
3
  module JobBoss
4
4
  class Boss
5
+ extend ActiveSupport::Memoizable
6
+
5
7
  class << self
6
8
  extend ActiveSupport::Memoizable
7
9
  # Used to set Boss configuration
@@ -9,16 +11,18 @@ module JobBoss
9
11
  # Boss.config.sleep_interval = 2
10
12
  def config
11
13
  require 'job_boss/config'
12
- @@config ||= Config.new
14
+ Config.new
13
15
  end
16
+ memoize :config
14
17
 
15
18
  # Used to queue jobs
16
19
  # Usage:
17
20
  # Boss.queue.math.is_prime?(42)
18
21
  def queue
19
22
  require 'job_boss/queuer'
20
- @@queuer ||= Queuer.new
23
+ Queuer.new
21
24
  end
25
+ memoize :queue
22
26
 
23
27
  # Used to queue jobs
24
28
  # Usage:
@@ -29,30 +33,34 @@ module JobBoss
29
33
  queue.send(controller).send(action, *args)
30
34
  end
31
35
 
32
- def logger
33
- @@config.log_path = resolve_path(@@config.log_path)
34
-
35
- require 'logger'
36
- Logger.new(@@config.log_path)
37
- end
38
- memoize :logger
39
-
40
36
  # If path starts with '/', leave alone. Otherwise, prepend application_root
41
37
  def resolve_path(path)
42
- if path == ?/ || path.match(/^#{@@config.application_root}/)
38
+ if path == ?/ || path.match(/^#{config.application_root}/)
43
39
  path
44
40
  else
45
- File.join(@@config.application_root, path)
41
+ File.join(config.application_root, path)
46
42
  end
47
43
  end
48
44
  end
49
45
 
46
+ def config
47
+ Boss.config
48
+ end
49
+
50
+ def logger
51
+ config.log_path = Boss.resolve_path(config.log_path)
52
+
53
+ require 'logger'
54
+ Logger.new(config.log_path)
55
+ end
56
+ memoize :logger
57
+
50
58
  def initialize(options = {})
51
- @@config.application_root ||= options[:working_dir]
52
- @@config.sleep_interval ||= options[:sleep_interval]
53
- @@config.employee_limit ||= options[:employee_limit]
54
- @@config.database_yaml_path ||= options[:database_yaml_path]
55
- @@config.jobs_path ||= options[:jobs_path]
59
+ config.application_root ||= options[:working_dir]
60
+ config.sleep_interval ||= options[:sleep_interval]
61
+ config.employee_limit ||= options[:employee_limit]
62
+ config.database_yaml_path ||= options[:database_yaml_path]
63
+ config.jobs_path ||= options[:jobs_path]
56
64
 
57
65
  @running_jobs = []
58
66
  end
@@ -63,13 +71,10 @@ module JobBoss
63
71
  require 'yaml'
64
72
 
65
73
  establish_active_record_connection
74
+ logger.info "Started ActiveRecord connection in '#{config.environment}' environment from database YAML: #{config.database_yaml_path}"
66
75
 
67
76
  require_job_classes
68
77
 
69
- require 'job_boss/job'
70
-
71
- migrate
72
-
73
78
  Signal.trap("HUP") do
74
79
  stop
75
80
  end
@@ -78,11 +83,12 @@ module JobBoss
78
83
  stop if Process.pid == BOSS_PID
79
84
  end
80
85
 
81
- Boss.logger.info "Job Boss started"
86
+ logger.info "Job Boss started"
87
+ logger.info "Employee limit: #{Boss.config.employee_limit}"
82
88
 
83
89
  while true
84
90
  unless (children_count = available_employees) > 0 && Job.pending.count > 0
85
- sleep(@@config.sleep_interval)
91
+ sleep(config.sleep_interval)
86
92
  next
87
93
  end
88
94
 
@@ -92,7 +98,7 @@ module JobBoss
92
98
  job = Job.pending.find_by_path(path)
93
99
  next if job.nil?
94
100
 
95
- job.dispatch
101
+ job.dispatch(self)
96
102
  @running_jobs << job
97
103
 
98
104
  children_count -= 1
@@ -103,11 +109,11 @@ module JobBoss
103
109
  end
104
110
 
105
111
  def stop
106
- Boss.logger.info "Stopping #{@running_jobs.size} running employees..."
112
+ logger.info "Stopping #{@running_jobs.size} running employees..."
107
113
 
108
114
  shutdown_running_jobs
109
115
 
110
- Boss.logger.info "Job Boss stopped"
116
+ logger.info "Job Boss stopped"
111
117
  end
112
118
 
113
119
  private
@@ -136,35 +142,34 @@ private
136
142
  def available_employees
137
143
  cleanup_running_jobs
138
144
 
139
- @@config.employee_limit - @running_jobs.size
145
+ config.employee_limit - @running_jobs.size
140
146
  end
141
147
 
142
148
  def establish_active_record_connection
143
- @@config.database_yaml_path = Boss.resolve_path(@@config.database_yaml_path)
149
+ config.database_yaml_path = Boss.resolve_path(config.database_yaml_path)
144
150
 
145
- raise "Database YAML file missing (#{@@config.database_yaml_path})" unless File.exist?(@@config.database_yaml_path)
151
+ raise "Database YAML file missing (#{config.database_yaml_path})" unless File.exist?(config.database_yaml_path)
146
152
 
147
- config = YAML.load(File.read(@@config.database_yaml_path))
153
+ config_data = YAML.load(File.read(config.database_yaml_path))
148
154
 
149
155
  ActiveRecord::Base.remove_connection
150
- ActiveRecord::Base.establish_connection(config[@@config.environment])
151
- end
152
-
153
- def require_job_classes
154
- @@config.jobs_path = Boss.resolve_path(@@config.jobs_path)
155
-
156
- raise "Jobs path missing (#{@@config.jobs_path})" unless File.exist?(@@config.jobs_path)
157
-
158
- Dir.glob(File.join(@@config.jobs_path, '*.rb')).each {|job_class| require job_class }
159
- end
156
+ ActiveRecord::Base.establish_connection(config_data[config.environment])
160
157
 
161
- def migrate
158
+ require 'job_boss/job'
162
159
  unless Job.table_exists?
163
160
  require 'migrate'
164
161
  CreateJobs.up
165
162
  end
166
163
  end
167
164
 
165
+ def require_job_classes
166
+ config.jobs_path = Boss.resolve_path(config.jobs_path)
167
+
168
+ raise "Jobs path missing (#{config.jobs_path})" unless File.exist?(config.jobs_path)
169
+
170
+ Dir.glob(File.join(config.jobs_path, '*.rb')).each {|job_class| require job_class }
171
+ end
172
+
168
173
  def kill_job(job)
169
174
  begin
170
175
  Process.kill("TERM", job.employee_pid.to_i)