Index: trunk/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- trunk/ippToPsps/jython/ipptopspsdb.py	(revision 31863)
+++ trunk/ippToPsps/jython/ipptopspsdb.py	(revision 31864)
@@ -61,5 +61,5 @@
     def getProcessedIDsForThisStage(self, batchType, startDate):
 
-        sql = "SELECT stage_id \
+        sql = "SELECT DISTINCT stage_id \
                FROM batch \
                WHERE batch_type = '" + batchType + "' \
@@ -157,45 +157,25 @@
     TODO
     '''
-    def getTotalFailedBatches(self, batchType, startTime, endTime=""):
-
-        sql = "SELECT COUNT(DISTINCT stage_id) \
+    def getFailedBatches(self, batchType, startTime, endTime=""):
+
+        sql = "SELECT DISTINCT stage_id \
                FROM batch \
                WHERE timestamp > '" + startTime + "' \
                AND batch_type = '" + batchType + "' \
-               AND !processed \
-               AND stage_id NOT IN \
-               (SELECT DISTINCT stage_id \
-                FROM batch \
-                WHERE timestamp > '" + startTime + "'  \
-                AND batch_type = '" + batchType + "' \
-                AND loaded_to_datastore)"
-
-        try:
-            rs = self.executeQuery(sql)
-            rs.first()
-            total = rs.getInt(1)
-        except:
-            self.logger.exception("Unable to count failed batches")
-
-        return total
-    '''
-    TODO
-    '''
-    def getTotalBatchesPublished(self, batchType, startTime, endTime=""):
-
-        sql = "SELECT COUNT(*) \
-               FROM batch \
-               WHERE timestamp > '" + startTime + "' \
-               AND batch_type = '" + batchType + "' \
-               AND loaded_to_datastore"
-
-        try:
-            rs = self.executeQuery(sql)
-            rs.first()
-            total = rs.getInt(1)
-        except:
-            self.logger.exception("Unable to count batches")
-
-        return total
+               AND !processed"
+
+        ids = []
+        try:
+            rs = self.executeQuery(sql)
+            while (rs.next()):
+                ids.append(rs.getInt(1))
+        except:
+            self.logger.exception("Can't query for failed ids in ipptopsps Db")
+
+        rs.close()
+
+        self.logger.debug("Found %d failed items for batchType='%s'" % (len(ids), batchType))
+
+        return ids
 
     '''
