Index: branches/simtest_nebulous_branches/ippTasks/pstamp.pro
===================================================================
--- branches/simtest_nebulous_branches/ippTasks/pstamp.pro	(revision 25061)
+++ branches/simtest_nebulous_branches/ippTasks/pstamp.pro	(revision 27840)
@@ -1,4 +1,8 @@
-
-#$VERBOSE = 3
+# pstamp.pro : Postage Stamp Server tasks
+
+check.globals
+
+$LOGSUBDIR = $LOGDIR/pstamp
+mkdir $LOGSUBDIR
 
 # these variables wil cycle through the known database names
@@ -8,11 +12,14 @@
 $pstampJob_DB = 0
 $pstampFin_DB = 0
+$pstampRev_DB = 0
+$pstampDep_DB = 0
 
 # set PS_DBSERVER if postage stamp database host is not the same as the value for DBSERVER in site.config
-# warning: no quotes around the two words. it cause it to get passed to pstamptool as one word
-# tricky to debug problem ensues
+# warning: no quotes around the two words. That causes the variable to get passed to pstamptool as one word
+# and a tricky to debug problem ensues
 # example:
-# $PSDBSERVER = -dbserver hostname
-if ($?PSDBSERVER == 0)
+# $PS_DBSERVER = -dbserver hostname
+
+if ($?PS_DBSERVER == 0)
     $PS_DBSERVER = ""
 end
@@ -22,8 +29,8 @@
     book init pstampJob
     book init pstampFinish
+    book init pstampDependent
 end
 
 pstamp.reset
-
 
 macro pstamp.on
@@ -51,5 +58,12 @@
         active true
     end
-end
+    task pstamp.job.revert
+        active true
+    end
+    task pstamp.dependent.load
+        active true
+    end
+end
+
 
 macro pstamp.off
@@ -76,4 +90,21 @@
         active false
     end
+    task pstamp.job.revert
+        active false
+    end
+    task pstamp.dependent.load
+        active true
+    end
+end
+
+macro pstamp.revert.on
+    task pstamp.job.revert
+        active true
+    end
+end
+macro pstamp.revert.off
+    task pstamp.job.revert
+        active false
+    end
 end
 
@@ -83,8 +114,10 @@
     periods     -poll $LOADPOLL
     periods     -exec 10
-    periods     -timeout 30
+    periods     -timeout 120
     npending    1
 
     task.exec
+        stdout NULL
+        stderr $LOGSUBDIR/pstamp.request.find.log
         if ($DB:n == 0)
             option DEFAULT
@@ -124,4 +157,6 @@
 
     task.exec
+        stdout $LOGSUBDIR/pstamp.request.load.log
+        stderr $LOGSUBDIR/pstamp.request.load.log
         $run = pstamptool -pendingreq
         if ($DB:n == 0)
@@ -134,4 +169,5 @@
         end
         add_poll_args run
+        add_poll_labels run
         command $run
     end
@@ -166,4 +202,6 @@
 
     task.exec
+        stdout $LOGSUBDIR/pstamp.request.run.log
+        stderr $LOGSUBDIR/pstamp.request.run.log
         book npages pstampRequest -var N
         if ($N == 0) break
@@ -177,8 +215,9 @@
         book getword pstampRequest $pageName uri -var URI
         book getword pstampRequest $pageName ds_outProduct -var PRODUCT
+        book getword pstampRequest $pageName label -var LABEL
 
         host anyhost
 
-        $run = pstamp_parser_run.pl --req_id $REQ_ID --uri $URI --product $PRODUCT --redirect-output
+        $run = pstamp_parser_run.pl --req_id $REQ_ID --uri $URI --product $PRODUCT --label $LABEL --redirect-output
 
         add_standard_args run
@@ -221,13 +260,18 @@
 
     task.exec
+        stdout $LOGSUBDIR/pstamp.finish.load.log
+        stderr $LOGSUBDIR/pstamp.finish.load.log
+        $run = pstamptool  -completedreq
         if ($DB:n == 0)
             option DEFAULT
-            command pstamptool  -completedreq
         else 
             option $DB:$pstampFin_DB
-            command pstamptool  -completedreq -dbname $DB:$pstampFin_DB $PS_DBSERVER
+            $run = $run -dbname $DB:$pstampFin_DB $PS_DBSERVER
             $pstampFin_DB ++
             if ($pstampFin_DB >= $DB:n) set pstampFin_DB = 0
         end
+        add_poll_args run
+        add_poll_labels run
+        command $run
     end
 
@@ -257,7 +301,10 @@
     periods     -poll $RUNPOLL
     periods     -exec $RUNEXEC
-    periods     -timeout 300
-
-    task.exec
+    periods     -timeout 2400
+    host        anyhost
+
+    task.exec
+        stdout $LOGSUBDIR/request.finish.run.log
+        stderr $LOGSUBDIR/request.finish.run.log
         book npages pstampFinish -var N
         if ($N == 0) break
@@ -315,13 +362,18 @@
 
     task.exec
+        stdout $LOGSUBDIR/pstamp.job.load.log
+        stderr $LOGSUBDIR/pstamp.job.load.log
+        $run = pstamptool -pendingjob
         if ($DB:n == 0)
             option DEFAULT
-            command pstamptool -pendingjob -limit 10
         else
             option $DB:$pstampJob_DB
-            command pstamptool -pendingjob -limit 10 -dbname $DB:$pstampJob_DB $PS_DBSERVER
+            $run = $run -dbname $DB:$pstampJob_DB $PS_DBSERVER
             $pstampJob_DB ++
             if ($pstampJob_DB >= $DB:n) set pstampJob_DB = 0
         end
+        add_poll_args run
+        add_poll_labels run 
+        command $run
     end
 
@@ -338,15 +390,16 @@
     end
 
+    task.exit   crash
+        showcommand crash
+    end
+
+    task.exit   timeout
+        showcommand timeout
+    end
+
     task.exit   default
         showcommand failure
     end
 
-    task.exit   crash
-        showcommand crash
-    end
-
-    task.exit   timeout
-        showcommand timeout
-    end
 end
 
@@ -357,6 +410,12 @@
 
     task.exec
+        stdout $LOGSUBDIR/pstamp.job.run.log
+        stderr $LOGSUBDIR/pstamp.job.run.log
         book npages pstampJob -var N
-        if ($N == 0) break
+        if ($N == 0) 
+            periods -exec $RUNEXEC
+            break
+        end
+        periods -exec 0.05
         
         book getpage pstampJob 0 -var pageName -key pantaskState INIT
@@ -371,4 +430,5 @@
         book getword pstampJob $pageName dbname -var DBNAME
         book getword pstampJob $pageName outputBase -var OUTPUT_BASE
+        book getword pstampJob $pageName options -var OPTIONS
 
         if ($VERBOSE > 1) 
@@ -378,5 +438,5 @@
         host anyhost
 
-        $run = pstamp_job_run.pl --job_id $JOB_ID --job_type $JOB_TYPE --rownum $ROWNUM --output_base $OUTPUT_BASE --redirect-output 
+        $run = pstamp_job_run.pl --job_id $JOB_ID --job_type $JOB_TYPE --rownum $ROWNUM --output_base $OUTPUT_BASE --options $OPTIONS --redirect-output 
         add_standard_args run
 
@@ -418,2 +478,188 @@
     end
 end
+
+task pstamp.job.revert
+    host        local
+
+    periods     -poll $LOADPOLL
+    periods     -exec 300
+    periods     -timeout 300
+    npending    1
+
+    task.exec
+        stdout $LOGSUBDIR/pstamp.job.revert.log
+        stderr $LOGSUBDIR/pstamp.job.revert.log
+        $run = pstamptool -revertjob -all
+        if ($DB:n == 0)
+            option DEFAULT
+        else 
+            $run = $run $PS_DBSERVER -dbname $DB:$pstampRev_DB
+            $pstampRev_DB ++
+            if ($pstampRev_DB >= $DB:n) set pstampRev_DB = 0
+        end
+        add_poll_args run
+        add_poll_labels run
+        command $run
+    end
+
+    task.exit $EXIT_SUCCESS
+        # nothing to do
+    end
+
+    task.exit   default
+        showcommand failure
+    end
+
+    task.exit   crash
+        showcommand crash
+    end
+
+    task.exit   timeout
+        showcommand timeout
+    end
+end
+
+task pstamp.dependent.load
+    host        local
+
+    periods     -poll $LOADPOLL
+    # XXX: create a macro for this time
+    periods     -exec 10
+#    periods     -exec $LOADEXEC
+    periods     -timeout 300
+    npending    1
+
+    task.exec
+        stdout $LOGSUBDIR/pstamp.dependent.load.log
+        stderr $LOGSUBDIR/pstamp.dependent.load.log
+        $run = pstamptool -pendingdependent
+        if ($DB:n == 0)
+            option DEFAULT
+        else
+            option $DB:$pstampDep_DB
+            $run = $run -dbname $DB:$pstampDep_DB $PS_DBSERVER
+            $pstampDep_DB ++
+            if ($pstampDep_DB >= $DB:n) set pstampDep_DB = 0
+        end
+        add_poll_args run
+        add_poll_labels run 
+        command $run
+    end
+
+    task.exit $EXIT_SUCCESS
+        ipptool2book stdout pstampDependent -key dep_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+
+        book npages pstampDependent -var N
+        if ($VERBOSE > 2)
+            book listbook pstampDependent
+        end
+
+        # delete existing entries in the appropriate pantaskStates
+        process_cleanup pstampDependent
+    end
+
+    task.exit   crash
+        showcommand crash
+    end
+
+    task.exit   timeout
+        showcommand timeout
+    end
+
+    task.exit   default
+        showcommand failure
+    end
+
+end
+
+task pstamp.dependent.run
+    periods     -poll $RUNPOLL
+    periods     -exec $RUNEXEC
+    periods     -timeout 300
+
+    task.exec
+#        stdout $LOGSUBDIR/pstamp.dependent.run.log
+#        stderr $LOGSUBDIR/pstamp.dependent.run.log
+        book npages pstampDependent -var N
+        if ($N == 0) 
+            periods -exec $RUNEXEC
+            break
+        end
+        periods -exec 0.05
+        
+        book getpage pstampDependent 0 -var pageName -key pantaskState INIT
+        if ("$pageName" == "NULL") break
+
+        #echo pageName: $pageName
+
+        book setword pstampDependent $pageName pantaskState RUN
+        book getword pstampDependent $pageName dep_id     -var DEP_ID
+        book getword pstampDependent $pageName state      -var STATE
+        book getword pstampDependent $pageName stage      -var STAGE
+        book getword pstampDependent $pageName stage_id   -var STAGE_ID
+        book getword pstampDependent $pageName component  -var COMPONENT
+        book getword pstampDependent $pageName imagedb    -var IMAGEDB
+        book getword pstampDependent $pageName rlabel     -var RLABEL
+#        book getword pstampDependent $pageName output_base -var OUTPUT_BASE
+        book getword pstampDependent $pageName need_magic -var NEED_MAGIC
+        book getword pstampDependent $pageName dbname     -var DBNAME
+
+        if ($VERBOSE > 1) 
+            book listpage pstampDependent $pageName
+        end
+
+        host anyhost
+
+        if ("$NEED_MAGIC" == "T")
+            $NEED_MAGIC="--need_magic"
+        else
+            $NEED_MAGIC=""
+        end
+
+        # XXX: use OUTPUT_BASE for this
+        $LOGFILE = /data/ipp053.0/home/bills/pstamp/logs/pstampdep.$DEP_ID.log
+#        echo logfile is $LOGFILE
+#        stdout $LOGFILE
+#        stderr $LOGFILE
+
+        $run = pstamp_checkdependent.pl --dep_id $DEP_ID --stage_id $STAGE_ID --stage $STAGE --component $COMPONENT --imagedb $IMAGEDB --rlabel $RLABEL $NEED_MAGIC
+        add_standard_args run
+
+        options $pageName
+
+        if ($VERBOSE > 1) 
+            echo command $run
+        end
+        command $run
+    end
+
+
+    task.exit $EXIT_SUCCESS
+        if ($VERBOSE > 1)
+            echo pstamp.dependent.run task.exit $DEP_ID status: $JOB_STATUS
+        end
+        process_exit pstampDependent $options:0 $JOB_STATUS
+    end
+    task.exit default
+        if ($VERBOSE > 1)
+            echo pstamp.job.run task.exit $DEP_ID status: $JOB_STATUS
+        end
+        showcommand failure
+        process_exit pstampDependent $options:0 $JOB_STATUS
+    end
+
+    task.exit crash
+        echo pstamp.job.run task.crash $DEP_ID status: $JOB_STATUS
+        process_exit pstampDependent $options:0 $JOB_STATUS
+        showcommand crash
+        book setword pstampDependent $options:0 pantaskState CRASH
+    end
+
+    task.exit timeout
+        echo pstamp.job.run task.timeout $DEP_ID status: $JOB_STATUS
+        process_exit pstampDependent $options:0 $JOB_STATUS
+        showcommand timeout
+        book setword pstampDependent $options:0 pantaskState TIMEOUT
+    end
+end
+
