Index: trunk/ippTasks/replicate.pro
===================================================================
--- trunk/ippTasks/replicate.pro	(revision 17531)
+++ trunk/ippTasks/replicate.pro	(revision 17531)
@@ -0,0 +1,135 @@
+## replicate.pro : tasks for data replication : -*- sh -*-
+## this file contains the tasks for maintaining duplicates as needed in Nebulous
+## these tasks use the books replicatePending and regPendingExp
+
+# test for required global variables
+check.globals
+
+$LOGSUBDIR = $LOGDIR/replicate
+exec mkdir -p $LOGSUBDIR
+
+book init replicatePending
+
+macro replicate.reset
+  book init replicatePending
+end
+
+macro replicate.status
+  book listbook replicatePending
+end
+
+macro replicate.on
+  task replicate.load
+    active true
+  end
+  task replicate.run
+    active true
+  end
+end
+
+macro replicate.off
+  task replicate.load
+    active false
+  end
+  task replicate.run
+    active false
+  end
+end
+
+# the replicate process interacts with only the single Nebulous server
+
+# select Nebulous objects which desire additional copies
+task	       replicate.load
+  host         local
+
+  # modify these after the tasks are tested
+  periods      -poll 60
+  periods      -exec 300
+  periods      -timeout 60
+  npending     1
+
+  # silently drop stdout
+  stdout NULL
+  stderr $LOGSUBDIR/replicate.log
+
+  # command does not need to be dynamic
+  command neb-load-replicants -limit 20
+
+  # success
+  task.exit $EXIT_SUCCESS
+    # convert 'stdout' to book format
+    ipptool2book stdout replicatePending -key neb_key -uniq -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook replicatePending
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup replicatePending
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# create the desired replicas
+task	       replicate.run
+  periods      -poll 5
+  periods      -exec 30
+  periods      -timeout 30
+
+  task.exec
+    book npages replicatePending -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+    
+    # look for new objects in replicatePending
+    book getpage replicatePending 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword replicatePending $pageName pantaskState RUN
+
+    # XXX what values do I need to get back?
+    book getword replicatePending $pageName exp_id       -var EXP_ID
+    book getword replicatePending $pageName tmp_exp_name -var TMP_EXP_NAME
+
+    ## generate output logfile name and convert URI to a PATH
+    sprintf logfile "%s/%s/%s.%s.reg.log" $WORKDIR $EXP_TAG $EXP_TAG $TMP_CLASS_ID
+    $logfile = `ipp_datapath.pl $logfile`
+
+    stdout $logfile
+    stderr $logfile
+    dirname $logfile -var outpath
+    mkdir $outpath
+
+    $run = replicate_object.pl --exp_id $EXP_ID --tmp_class_id $TMP_CLASS_ID --tmp_exp_name $TMP_EXP_NAME --uri $URI
+    add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  # default exit status
+  task.exit default
+    process_exit replicatePending $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword replicatePending $options:0 pantaskState TIMEOUT
+  end
+end
+
