<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -232,8 +232,11 @@ DESCRIPTION
   
     :priority =&gt; any number, including negative ones.  default is zero.
   
-    :tag =&gt; a tag added to the job.  simply makes searching easier.
+    :tag =&gt; a tag added to the job.  makes searching easier, and can also be
+            used as filters in runners via --only-tag and --except-tag options.
   
+    :dependency_id =&gt; a job id which has to be run before this job
+    
     :env =&gt; a hash specifying any additional environment vars the background
             process should have.
   
@@ -253,6 +256,11 @@ DESCRIPTION
                      :tag =&gt; 'dynamic ruby code'
   
     jobs Bj.submit array_of_commands, :priority =&gt; 451 
+
+    # Dependency example
+    
+    primary_job = Bj.submit './script/runner lib/jobs/primary.rb'
+    Bj.submit './script/runner lib/jobs/post_primary.rb', :dependency_id =&gt; primary_job.first.bj_job_id
     
   when jobs are run, they are run in RAILS_ROOT.  various attributes are
   available *only* once the job has finished.  you can check whether or not a
@@ -297,6 +305,10 @@ PARAMETERS
   --log=log, -l (0 ~&gt; log=STDERR) 
       set the logfile 
   --help, -h 
+  --only-tag=tag
+      Only run jobs tagged with this tag
+  --except-tag=tag
+      Run all jobs except those tagged with this tag
 
 AUTHOR
   ara.t.howard@gmail.com</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -378,6 +378,14 @@ txt
       argument :required
     }
     option(&quot;--daemon&quot;){}
+    option(&quot;--only-tag&quot;){
+      argument :required
+      description &quot;Only execute jobs with this tag name&quot;
+    }
+    option(&quot;--except-tag&quot;){
+      argument :required
+      description &quot;Excute all jobs which don't have this tag name&quot;
+    }
 
     def run
       options = {}
@@ -388,7 +396,7 @@ txt
       end
 =end
 
-      %w[ forever ppid wait limit ].each do |key|
+      %w[ forever ppid wait limit only-tag except-tag ].each do |key|
         options[key.to_sym] = param[key].value if param[key].given?
       end
 </diff>
      <filename>bin/bj</filename>
    </modified>
    <modified>
      <diff>@@ -94,13 +94,11 @@ class Bj
 
       def key ppid = 0
         ppid ||= 0
-        #&quot;#{ Bj.rails_env }.#{ ppid }.pid&quot;
-        &quot;runner.#{ ppid }.pid&quot;
+        &quot;#{ Bj.rails_env }.#{ ppid }.pid&quot;
       end
 
       def no_tickle_key 
-        # &quot;#{ Bj.rails_env }.no_tickle&quot;
-        &quot;no_tickle&quot;
+        &quot;#{ Bj.rails_env }.no_tickle&quot;
       end
 
       def start options = {}
@@ -156,7 +154,9 @@ class Bj
         wait = options[:wait] || 42
         limit = options[:limit]
         forever = options[:forever]
-
+        only_tag = options[&quot;only-tag&quot;.to_sym]
+        except_tag = options[&quot;except-tag&quot;.to_sym]
+        
         limit = false if forever
         wait = Integer wait
         loopno = 0
@@ -186,19 +186,29 @@ class Bj
 
               Bj.transaction(options) do
                 now = Time.now
-
-                job = Bj::Table::Job.find :first,
-                                          :conditions =&gt; [&quot;state = ? and submitted_at &lt;= ?&quot;, &quot;pending&quot;, now],
-                                          :order =&gt; &quot;priority DESC, submitted_at ASC&quot;, 
-                                          :limit =&gt; 1,
-                                          :lock =&gt; true
+                
+                conditions = &quot;&quot;
+                conditions += &quot;and tag = '#{only_tag}'&quot; if only_tag
+                conditions += &quot;and tag != '#{except_tag}'&quot; if except_tag
+                
+                jobs = Bj::Table::Job.find :all,
+                                           :conditions =&gt; [&quot;state = ? and submitted_at &lt;= ? #{conditions}&quot;, &quot;pending&quot;, now],
+                                           :order =&gt; &quot;priority DESC, submitted_at ASC&quot;,
+                                           :lock =&gt; true
+
+                job = nil
+                jobs.each do |j|
+                  job = j and break if j.dependency_id.nil?
+                  
+                  dependency = Bj::Table::Job.find j.dependency_id  
+                  job = j and break if dependency.state == 'finished'
+                end
                 throw :no_jobs unless job
 
-
                 Bj.logger.info{ &quot;#{ job.title } - started&quot; }
 
                 command = job.command
-                env = job.env ? YAML.load(job.env) : {}
+                env = job.env || {}
                 stdin = job.stdin || ''
                 stdout = job.stdout || ''
                 stderr = job.stderr || ''</diff>
      <filename>lib/bj/runner.rb</filename>
    </modified>
    <modified>
      <diff>@@ -102,7 +102,8 @@ class Bj
             t.column &quot;priority&quot;       , :integer
             t.column &quot;tag&quot;            , :text
             t.column &quot;is_restartable&quot; , :integer
-
+            t.column &quot;dependency_id&quot;  , :integer
+            
             t.column &quot;submitter&quot;      , :text
             t.column &quot;runner&quot;         , :text
             t.column &quot;pid&quot;            , :integer</diff>
      <filename>lib/bj/table.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5d9a4efcdd9b754e9f6cc04fd21ab6cf0d02a38f</id>
    </parent>
  </parents>
  <author>
    <name>Michael Murray</name>
    <email>mdmurray@gmail.com</email>
  </author>
  <url>http://github.com/howcast/backgroundjob/commit/c25a6a6e1cf78fc02a2335ebf0f454715a4a3ac9</url>
  <id>c25a6a6e1cf78fc02a2335ebf0f454715a4a3ac9</id>
  <committed-date>2008-05-20T23:03:56-07:00</committed-date>
  <authored-date>2008-05-20T23:03:56-07:00</authored-date>
  <message>Adds more options for distributed bj:

 - Workers which respect tags: Workers can now be started with --only-tag=tag and --except-tag=tag options which will allow for them to only run jobs with these conditions. This is useful if you have specialized worker environments where certain workers can only run or not run particular jobs.

 - Dependencies: With a distributed system it may be important that some jobs are run consecutively, with the tag filters it can get even harder to avoid deadlock situations in the job queue. This enhancement allows jobs to be submitted with a dependency_id (another bj_job_id) which must be completed before the job being submitted is started. See the updated README for an example.</message>
  <tree>f163692318cbadee4723657578e4a872a82a4762</tree>
  <committer>
    <name>Michael Murray</name>
    <email>mdmurray@gmail.com</email>
  </committer>
</commit>
