Index: branches/pap/ippTasks/dist.pro
===================================================================
--- branches/pap/ippTasks/dist.pro	(revision 23948)
+++ branches/pap/ippTasks/dist.pro	(revision 25027)
@@ -5,5 +5,5 @@
 
 #$LOGSUBDIR = $LOGDIR/dist
-#exec mkdir -p $LOGSUBDIR
+mkdir $LOGSUBDIR
 
 ### Initialise the books containing the tasks to do
@@ -14,4 +14,5 @@
 $distToProcess_DB = 0
 $distToAdvance_DB = 0
+$distQueue_DB = 0
 
 ### Check status of tasks
@@ -41,4 +42,9 @@
     active true
   end
+  task dist.queueruns
+#   We aren't ready to run this task yet. It will queue much too much 
+#    active true
+    active false
+  end
 end
 macro dist.off
@@ -53,4 +59,7 @@
   end
   task dist.advance.run
+    active false
+  end
+  task dist.queueruns
     active false
   end
@@ -80,4 +89,5 @@
     end
     add_poll_args run
+    add_poll_labels run
     command $run
   end
@@ -113,5 +123,10 @@
   task.exec
     book npages distToProcess -var N
-    if ($N == 0) break
+    if ($N == 0) 
+        periods -exec 10
+        break
+    end
+    periods -exec 0.05
+
     if ($NETWORK == 0) break
     
@@ -155,5 +170,15 @@
 #    set.host.for.camera $CAMERA $MAGIC_ID
 #    set.workdir.by.camera $CAMERA $MAGIC_ID $WORKDIR_TEMPLATE $default_host WORKDIR
-    host anyhost
+#    host anyhost
+
+
+    substr $COMPONENT 0 3 COMP_HEAD
+    if ("$COMP_HEAD" == "sky")
+        set.host.for.skycell $COMPONENT
+    else 
+        # assume component is a class_id, if not we will default to anyhost
+        set.host.for.camera $CAMERA $COMPONENT
+    end
+
 
     sprintf logfile "%s/dist.%s.%s.log" $OUTDIR $DIST_ID $COMPONENT
@@ -211,4 +236,5 @@
     end
     add_poll_args run
+    add_poll_labels run
     command $run
   end
@@ -257,4 +283,5 @@
     book getword distToAdvance $pageName outdir -var OUTDIR
     book getword distToAdvance $pageName clean -var CLEAN
+    book getword distToAdvance $pageName dbname -var DBNAME
     $EXTRA_ARGS = ""
     if ("$CLEAN" == "T")
@@ -293,2 +320,63 @@
 end
 
+task	       dist.queueruns
+#  host         local
+
+  periods      -poll $RUNPOLL
+  periods      -exec 30
+  periods      -timeout 45
+  npending     1
+
+  active false
+
+#  stdout $LOGDIR/dist.queuruns
+#  stderr $LOGDIR/dist.queueruns
+
+  task.exec
+    $MYARGS = ""
+    # assume that we need magic unless we are running simtest
+    if ($?SIMTEST_CAMERA != 0)
+        $MYARGS = --no_magic
+    end
+
+    $run = dist_queue_runs.pl $MYARGS --stage_limit 16 --logfile $LOGDIR/dist.queueruns
+
+    if ($DB:n == 0)
+       $DBNAME = DEFAULT
+    else
+      # save the DB name for add_standard_args
+      $DBNAME =  $DB:$distQueue_DB
+      $distQueue_DB ++
+      if ($distQueue_DB >= $DB:n) set distQueue_DB = 0
+    end
+
+    host anyhost
+
+    add_standard_args run
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  task.exit     $EXIT_SUCCESS
+    # nothing to do
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+  end
+
+  # operation timed out?
+  task.exit    crash
+    showcommand crash
+  end
+end
