Index: trunk/pstamp/scripts/pstamp_finish.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_finish.pl	(revision 18533)
+++ trunk/pstamp/scripts/pstamp_finish.pl	(revision 18587)
@@ -31,12 +31,14 @@
 
 
-my ( $dbname, $limit, $verbose, $save_temps );
+my ( $req_id, $req_name, $product, $dbname, $verbose, $save_temps );
 
 # the char to the right of the bar may be used as a single - alias for the longer name
 # for example --input and -i are equivalent
 GetOptions(
-	   'limit=s'    => \$limit,
+           'req_id=s'   => \$req_id,
+           'req_name=s' => \$req_name,
+           'product=s'  => \$product,
 	   'dbname=s'   => \$dbname,
-	   'verbose'  => \$verbose,
+	   'verbose'    => \$verbose,
 	   'save-temps' => \$save_temps,
 ) or pod2usage( 2 );
@@ -62,38 +64,5 @@
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
-my @requests;
 {
-    my $command = "$pstamptool -completedreq";
-    $command   .= " -limit $limit" if $limit;
-    $command   .= " -dbname $dbname" if $dbname;
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => $verbose);
-    unless ($success) {
-        die("Unable to perform $command error code: $error_code");
-    }
-    my $output = join "", @$stdout_buf;
-    if (!$output) {
-        if ($verbose) {
-            print STDERR "no completed requests pending\n"
-        }
-        exit 0;
-    }
-    my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
-
-    my $requests = parse_md_list($metadata);
-
-    @requests = @$requests
-}
-
-foreach my $req (@requests) {
-    my $req_id = $req->{req_id};
-
-    my $product = $req->{outProduct};
-    die "outProduct in request is null" if !$product;
-
-    my $req_name = $req->{name};
-    die "request name is null" if !$req_name;
-
-
     # set the output fileset's name to the request name.
     my $fileset = $req_name;
@@ -156,6 +125,4 @@
             # including those that produced no jobs.
             # for now add an entry for rownum 1 and a phony error code.
-            #
-            # possible fix: have pstampparse add a dummy job with state=stop and a fault code
             # we've included parse_results.txt to the fileset if it exists
             #
@@ -169,5 +136,5 @@
             my $jobs = parse_md_list($metadata);
 
-            @jobs = @$jobs
+            @jobs = @$jobs;
         }
     }
@@ -201,5 +168,6 @@
             }
         } else {
-            die "Unknown jobType: $job_type";
+            print STDERR "Unknown jobType: $job_type";
+            next;
         }
     }
@@ -235,5 +203,4 @@
     # set the request's state to stop
     {
-        
         my $command = "$pstamptool -processedreq -req_id $req_id -state stop -fault $request_fault";
         $command   .= " -dbname $dbname" if $dbname;
@@ -245,2 +212,16 @@
     }
 }
+sub stop_request {
+    my $req_id = shift;
+    my $fault  = shift;
+    my $dbname = shift;
+
+    my $command = "$pstamptool -processedreq -req_id $req_id -state stop -fault $fault";
+    $command   .= " -dbname $dbname" if $dbname;
+
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        die("Unable to perform $command error code: $error_code");
+    }
+}
