Index: /trunk/pstamp/scripts/pstamp_queue_requests.pl
===================================================================
--- /trunk/pstamp/scripts/pstamp_queue_requests.pl	(revision 18233)
+++ /trunk/pstamp/scripts/pstamp_queue_requests.pl	(revision 18234)
@@ -2,19 +2,26 @@
 #
 # pstamp_queue_reqests.pl
+#
 # Query registered data stores for new postage stamp requests and add them to
 # the database of pending requests.
 #
 
-# XXX TODO: need to take dbname as a paramter
-
 use warnings;
 use strict;
 
-my $verbosity = 0;
+use Getopt::Long qw( GetOptions );
 
 use Sys::Hostname;
 my $host = hostname();
 
-if ($verbosity) {
+my $verbose;
+my $dbname;
+
+GetOptions(
+    'verbose'       =>  \$verbose,
+    'dbname=s'      =>  \$dbname,
+);
+
+if ($verbose) {
     print STDERR "\n\n";
     print STDERR "Starting script $0 on $host\n\n";
@@ -56,8 +63,11 @@
 {
     my $command = "$pstamptool -datastore";
+    $command .= " -dbname $dbname" if $dbname;
+
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => $verbosity);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-        die("Unable to perform pstamptool -datastore: $error_code >> 8");
+        my $rc = $error_code >> 8;
+        die("Unable to perform pstamptool -datastore: $rc");
     }
 
@@ -96,5 +106,5 @@
         $command .= " --last_fileset $ds->{lastFileset}" if $ds->{lastFileset};
         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-            run(command => $command, verbose => $verbosity);
+            run(command => $command, verbose => $verbose);
         unless ($success) {
             die("Unable to perform $command: $error_code");
@@ -115,4 +125,6 @@
     # each line contains a fileset
     #
+    # XXX: we probably should set a limit on the number of these we process
+    # otherwise this could take a long time and the task could time out
     foreach my $line (@lines) {
         # parse the line into fields split by whitespace
@@ -125,5 +137,5 @@
             my $command = "$dsfilesetls --uri $uri";
             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-                    run(command => $command, verbose => $verbosity);
+                    run(command => $command, verbose => $verbose);
             unless ($success) {
                 die("Unable to perform $command: $error_code");
@@ -148,25 +160,26 @@
             {
                 my $command = "$pstamptool -addreq -uri $req_uri -ds_id $ds_id -out_fileset $outProduct/$fs_name";
+                $command .= " -dbname $dbname" if $dbname;
                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-                        run(command => $command, verbose => $verbosity);
+                        run(command => $command, verbose => $verbose);
                     unless ($success) {
-                            # XXX: what do we do now?
-                            die("Unable to perform $command: $error_code");
+                        # XXX: what do we do now?
+                        die("Unable to perform $command: $error_code");
                     }
             }
             $lastFileset = $fs_name;
-            # we only allow one request file per fileset
-            # XXX TODO: maybe Relax this restriction
-            last;
         }
     }
 
-    ## now update the data store table with the last_fileset
+    ## now update the last_fileset column in pstampDataStore
+    ## XXX: we should probably do this before we process the fileset. Otherwise 
+    ## if we get an error from pstamptool we'll get stuck processing it over and over.
     if ($lastFileset) {
         # print "last fileset: $lastFileset\n";
         {
         my $command = "$pstamptool -ds_id $ds_id -moddatastore -last_fileset $lastFileset";
+        $command .= " -dbname $dbname" if $dbname;
         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-            run(command => $command, verbose => $verbosity);
+            run(command => $command, verbose => $verbose);
             unless ($success) {
                 die("Unable to perform pstamptool -moddatastore: $error_code");
