Index: /trunk/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- /trunk/ippToPsps/jython/ipptopspsdb.py	(revision 32219)
+++ /trunk/ippToPsps/jython/ipptopspsdb.py	(revision 32220)
@@ -351,5 +351,5 @@
     Have we already processed and published this batch?
     '''
-    def alreadyProcessed(self, batchType, stage_id):
+    def alreadyProcessed(self, batchType, stage_id, epoch, dvoGpc1Label):
 
         sql = "SELECT COUNT(*) \
@@ -357,4 +357,6 @@
                WHERE stage_id = " + str(stage_id) + " \
                AND batch_type = '" + batchType + "' \
+               AND timestamp > '" + epoch + "' \
+               AND dvo_db = '" + dvoGpc1Label + "' \
                AND processed = 1 \
                AND loaded_to_datastore = 1"
@@ -364,5 +366,5 @@
             rs.first()
             if rs.getInt(1) > 0: 
-                self.logger.error("Batch with stage_id = "+str(stage_id) + " has already been processed and published to datastore")
+                self.logger.errorPair(str(stage_id) + " has already been published", "skipping")
                 return True
             else: 
@@ -370,4 +372,28 @@
         except:
             self.logger.exception("Unable to check whether this batch has already been processed")
+
+    '''
+    Has this stage_id consistently failed to process?
+    '''
+    def consistentlyFailed(self, batchType, stage_id, epoch, dvoGpc1Label, count):
+
+        sql = "SELECT COUNT(*) \
+               FROM batch \
+               WHERE stage_id = " + str(stage_id) + " \
+               AND batch_type = '" + batchType + "' \
+               AND timestamp > '" + epoch + "' \
+               AND dvo_db = '" + dvoGpc1Label + "' \
+               AND processed != 1"
+
+        try:
+            rs = self.executeQuery(sql)
+            rs.first()
+            if rs.getInt(1) >= count: 
+                self.logger.errorPair(str(stage_id) + " has failed %d times" % count, "skipping")
+                return True
+            else: 
+                return False
+        except:
+            self.logger.exception("Unable to check whether this batch has consistently failed")
 
      
