Index: trunk/ippTasks/automate.pro
===================================================================
--- trunk/ippTasks/automate.pro	(revision 16492)
+++ trunk/ippTasks/automate.pro	(revision 16570)
@@ -26,15 +26,14 @@
   end
   queueload tmp -x "cat $MODULES:0/$1"
-  ipptool2book tmp automate -key name -uniq -setword pantaskState INIT
+  ipptool2book tmp automate -key name -uniq -setword pantaskState INIT.BLOCK
   queuedelete tmp
 end
 
-$automate_Ncheck = 0
-
-task automate.check
+$automate_Nblock = -1
+task automate.block
   host         local
 
   periods      -poll 1
-  periods      -exec 10
+  periods      -exec 5
   periods      -timeout 30
   active       true
@@ -42,36 +41,42 @@
 
   task.exec
-    local N Npage pageName
+    local Npage pageName
 
     # how many pages are waiting to be started?
-    book npages automate -var N -key pantaskState INIT
-    if ($N == 0) break
-
-    # total number of pages in book
-    book npages automate -var Npage
-
-    $automate_Ncheck ++
-    if ($automate_Ncheck >= $Npage) set automate_Ncheck = 0
-
-    # search the automate book for an entry which is unstarted (state INIT) 
-    book getpage automate $automate_Ncheck -var pageName -key pantaskState INIT
-    if ("$pageName" == "NULL") break 
+    book npages automate -var Npage -key pantaskState INIT.BLOCK
+    if ($Npage == 0) 
+      echo "no entries in INIT.BLOCK state"
+      break
+    end
+
+    # cycle over the number of INIT.BLOCK pages: no point to loop over the others
+    $automate_Nblock ++
+    if ($automate_Nblock >= $Npage) set automate_Nblock = 0
+    echo "automate.block $automate_Nblock"
+
+    # search the automate book for an entry which is unstarted (state INIT.BLOCK) 
+    book getpage automate $automate_Nblock -var pageName -key pantaskState INIT.BLOCK
+    if ("$pageName" == "NULL") 
+      echo "entry $automate_Nblock not in INIT.BLOCK state"
+      break 
+    end
  
-    book getword automate $pageName check -var checkCommand
-    if (("$checkCommand" == "NULL") || ("$checkCommand" == "NONE"))
-      # if there is no check needed, we can immediate progress to READY
-      book setword automate $pageName pantaskState READY
-      break
-    end
-
-    book setword automate $pageName pantaskState CHECK
+    book getword automate $pageName block -var blockCommand
+    if (("$blockCommand" == "NULL") || ("$blockCommand" == "NONE"))
+      # if there is no block needed, we can immediate progress to the next stage (INIT.CHECK)
+      book setword automate $pageName pantaskState INIT.CHECK
+      echo "$pageName is ready : INIT.CHECK"
+      break
+    end
+
+    book setword automate $pageName pantaskState RUN.BLOCK
 
     if ($VERBOSE >= 1)
-      echo "starting automate check for $pageName"
-      echo "command $checkCommand"
+      echo "starting automate block for $pageName"
+      echo "command $blockCommand"
     end
 
     options $pageName
-    command $checkCommand
+    command $blockCommand
   end
 
@@ -80,4 +85,6 @@
 
     $pageName = $options:0
+
+    echo "complete $pageName test, checking results"
 
     # convert 'stdout' to book format
@@ -88,22 +95,35 @@
     end
 
+    # if the block test returns any valid pages (valid results), the block is set, don't move to check
     book npages detExp -var Npage 
-    if ($Npage == 0) break
-
-    # we should have launched only a single detRun
-    book setword automate $pageName pantaskState READY
+    if ($Npage == 0) 
+      echo "$pageName is not blocked, ready for CHECK"
+      book setword automate $pageName pantaskState INIT.CHECK
+    else
+      echo "$pageName is blocked, not ready for CHECK"
+      book setword automate $pageName pantaskState INIT.BLOCK
+    end
 
     # drop the detExt book after we've grabbed the state
     book delete detExp
   end
-end
-
-$automate_Nlaunch = 0
-
-task automate.launch
+
+  # all failures here (what state?)
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+$automate_Ncheck = -1
+task automate.check
   host         local
 
   periods      -poll 1
-  periods      -exec 10
+  periods      -exec 5
   periods      -timeout 30
   active       true
@@ -111,28 +131,123 @@
 
   task.exec
-    local N Npage pageName
+    local Npage pageName
 
     # how many pages are waiting to be started?
-    book npages automate -var N -key pantaskState READY
-    if ($N == 0) break
-
-    # total number of pages in book
-    book npages automate -var Npage
-
+    book npages automate -var Npage -key pantaskState INIT.CHECK
+    if ($Npage == 0) 
+      echo "no entries in INIT.CHECK state"
+      break
+    end
+
+    # cycle over the number of INIT.CHECK pages: no point to loop over the others
+    $automate_Ncheck ++
+    if ($automate_Ncheck >= $Npage) set automate_Ncheck = 0
+    echo "automate.check $automate_Ncheck"
+
+    # search the automate book for an entry which is unstarted (state INIT.CHECK) 
+    book getpage automate $automate_Ncheck -var pageName -key pantaskState INIT.CHECK
+    if ("$pageName" == "NULL") 
+      echo "entry $automate_Ncheck not in INIT.CHECK state"
+      break 
+    end
+ 
+    book getword automate $pageName check -var checkCommand
+    if (("$checkCommand" == "NULL") || ("$checkCommand" == "NONE"))
+      # if there is no check needed, we can immediate progress to the next stage (INIT.LAUNCH)
+      book setword automate $pageName pantaskState INIT.LAUNCH
+      echo "$pageName is ready : INIT.LAUNCH"
+      break
+    end
+
+    book setword automate $pageName pantaskState RUN.CHECK
+
+    if ($VERBOSE >= 1)
+      echo "starting automate check for $pageName"
+      echo "command $checkCommand"
+    end
+
+    options $pageName
+    command $checkCommand
+  end
+
+  task.exit $EXIT_SUCCESS
+    local pageName Npage
+
+    $pageName = $options:0
+
+    echo "complete $pageName test, checking results"
+
+    # convert 'stdout' to book format
+    # XXX to use other tests, we'll need to modify this 
+    ipptool2book stdout detExp -key det_id -uniq
+    if ($VERBOSE > 2)
+      book listbook detExp
+    end
+
+    book npages detExp -var Npage 
+    if ($Npage == 0) 
+      echo "$pageName not ready for LAUNCH"
+      book setword automate $pageName pantaskState INIT.CHECK
+    else
+      echo "$pageName is ready for LAUNCH"
+      book setword automate $pageName pantaskState INIT.LAUNCH
+    end
+
+    # drop the detExt book after we've grabbed the state
+    book delete detExp
+  end
+
+  # all failures here (what state?)
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+$automate_Nlaunch = 0
+task automate.launch
+  host         local
+
+  periods      -poll 1
+  periods      -exec 5
+  periods      -timeout 30
+  active       true
+  npending     1
+
+  task.exec
+    local Npage pageName
+
+    # how many pages are waiting to be started?
+    book npages automate -var Npage -key pantaskState INIT.LAUNCH
+    if ($Npage == 0) 
+      echo "no entries in INIT.LAUNCH state"
+      break
+    end
+
+    # cycle over the number of INIT.LAUNCH pages: no point to loop over the others
     $automate_Nlaunch ++
     if ($automate_Nlaunch >= $Npage) set automate_Nlaunch = 0
-
-    # search the automate book for an entry which is ready (state READY) 
-    book getpage automate $automate_Nlaunch -var pageName -key pantaskState READY
-    if ("$pageName" == "NULL") break 
+    echo "automate.launch $automate_Nlaunch"
+
+    # search the automate book for an entry which is unstarted (state INIT.LAUNCH) 
+    book getpage automate $automate_Nlaunch -var pageName -key pantaskState INIT.LAUNCH
+    if ("$pageName" == "NULL") 
+      echo "entry $automate_Nlaunch not in INIT.LAUNCH state"
+      break 
+    end
  
     book getword automate $pageName launch -var launchCommand
     if (("$launchCommand" == "NULL") || ("$launchCommand" == "NONE"))
-      # if there is no launch needed, we can immediate progress to READY
-      book setword automate $pageName pantaskState DONE
-      break
-    end
-
-    book setword automate $pageName pantaskState LAUNCH
+      # if there is no launch needed, we can immediate progress to the next stage (INIT.LAUNCH)
+      book setword automate $pageName pantaskState INIT.LAUNCH
+      echo "$pageName is ready : INIT.LAUNCH"
+      break
+    end
+
+    book setword automate $pageName pantaskState RUN.LAUNCH
 
     if ($VERBOSE >= 1)
@@ -146,10 +261,21 @@
 
   task.exit $EXIT_SUCCESS
-    local pageName
+    local pageName Npage
 
     $pageName = $options:0
 
-    # we should have launched only a single detRun
-    book setword automate $pageName pantaskState DONE
-  end
-end
+    echo "completed $pageName launch"
+    book setword automate $pageName pantaskState DONE.LAUNCH
+  end
+
+  # all failures here (what state?)
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
