Changeset 32461
- Timestamp:
- Sep 29, 2011, 3:23:06 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/ipptopspsdb.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/ipptopspsdb.py
r32452 r32461 20 20 super(IppToPspsDb, self).__init__(logger, doc, "ipptopspsdatabase") 21 21 22 ''' 23 Creates a new batch 24 ''' 25 def createNewBatch(self, batchType, stageID, survey, dvoDb, datastoreProduct): 26 27 sql = "INSERT INTO batch ( \ 28 batch_type, \ 29 stage_id, \ 30 survey, \ 31 dvo_db, \ 32 datastore_product \ 33 ) VALUES ( \ 34 '" + batchType + "', \ 35 " + str(stageID) + ", \ 36 '" + survey + "', \ 37 '" + dvoDb + "', \ 38 '" + datastoreProduct + "' \ 39 )" 40 41 self.execute(sql) 42 43 sql = "SELECT MAX(batch_id) FROM batch" 44 45 batchID = -1; 46 47 try: 48 rs = self.executeQuery(sql) 49 rs.first() 50 batchID = rs.getInt(1) 51 except: 52 self.logger.exception("Unable to get batch ID") 53 54 self.logger.debug("Created new batch in ippToPsps database with batchID = %d" % batchID) 55 56 return batchID; 22 self.MAX_FAILS = 3 57 23 58 24 ''' … … 132 98 Returns a list of processed batch IDs that have not yet been loaded to the ODM 133 99 ''' 134 def get BatchIDsUnloadedToODM(self, epoch, dvoGpc1Label):100 def getUnloadedBatchIDs(self, epoch, dvoGpc1Label, batchType): 135 101 136 102 sql = "SELECT DISTINCT batch_id \ … … 139 105 AND dvo_db = '" + dvoGpc1Label + "' \ 140 106 AND loaded_to_datastore = 1 \ 107 AND batch_type = '" + batchType + "' \ 141 108 AND loaded_to_ODM = 0" 142 109 … … 157 124 158 125 ''' 159 Returns a list of processed batch IDs that have not failed to load and arenot yet merged, for this epoch and dvo label160 ''' 161 def getUn finishedBatchIDs(self, epoch, dvoGpc1Label):126 Returns a list of processed batch IDs that are merge_worthy, but not yet merged, for this epoch and dvo label 127 ''' 128 def getUnmergedBatchIDs(self, epoch, dvoGpc1Label, batchType): 162 129 163 130 sql = "SELECT DISTINCT batch_id \ … … 165 132 WHERE timestamp > '" + epoch + "' \ 166 133 AND dvo_db = '" + dvoGpc1Label + "' \ 167 AND loaded_to_datastore = 1 \ 168 AND merged != 1 \ 169 AND loaded_to_ODM != -1" 170 171 172 ids = [] 173 try: 174 rs = self.executeQuery(sql) 175 while (rs.next()): 176 ids.append(rs.getInt(1)) 177 except: 178 self.logger.exception("Can't query for unfinished batch ids in ipptopsps Db") 179 180 rs.close() 181 182 self.logger.debug("Found %d unfinished items" % len(ids)) 134 AND loaded_to_ODM = 1 \ 135 AND batch_type = '" + batchType + "' \ 136 AND merged != 1" 137 138 ids = [] 139 try: 140 rs = self.executeQuery(sql) 141 while (rs.next()): 142 ids.append(rs.getInt(1)) 143 except: 144 self.logger.exception("Can't query for unmerged batch ids in ipptopsps Db") 145 146 rs.close() 147 148 self.logger.debug("Found %d un-merged items" % len(ids)) 183 149 184 150 return ids … … 300 266 ''' 301 267 def getStages(self): 302 return ['processed', 'loaded_to_datastore', 'loaded_to_ODM', 'merge_worthy', ' merged', 'deleted_datastore', 'deleted_dxlayer', 'deleted_local']268 return ['processed', 'loaded_to_datastore', 'loaded_to_ODM', 'merge_worthy', 'deleted_datastore', 'merged', 'deleted_dxlayer', 'deleted_local'] 303 269 304 270 ''' … … 328 294 def getTimeOfLastBatchPublished(self, batchType, epoch, dvoGpc1Label): 329 295 330 minutes = None296 seconds = None 331 297 332 298 sql = "SELECT TIMESTAMPDIFF(SECOND, timestamp, now()) \ … … 427 393 428 394 ''' 395 Is someone processing this item right now? Checks whether this was attempted within the last 2 HOUR 396 ''' 397 def processingNow(self, batchType, stage_id, epoch, dvoGpc1Label): 398 399 sql = "SELECT COUNT(*) \ 400 FROM batch \ 401 WHERE stage_id = " + str(stage_id) + " \ 402 AND batch_type = '" + batchType + "' \ 403 AND dvo_db = '" + dvoGpc1Label + "' \ 404 AND timestamp BETWEEN now() - INTERVAL 2 HOUR AND now()" 405 406 try: 407 rs = self.executeQuery(sql) 408 rs.first() 409 if rs.getInt(1) > 0: 410 self.logger.errorPair(str(stage_id) + " is already being processed", "skipping") 411 return True 412 else: 413 return False 414 except: 415 self.logger.exception("Unable to check whether this batch is being processed") 416 417 ''' 429 418 Have we already processed and published this batch? 430 419 ''' … … 454 443 Has this stage_id consistently failed to process? 455 444 ''' 456 def consistentlyFailed(self, batchType, stage_id, epoch, dvoGpc1Label , count):445 def consistentlyFailed(self, batchType, stage_id, epoch, dvoGpc1Label): 457 446 458 447 sql = "SELECT COUNT(*) \ … … 467 456 rs = self.executeQuery(sql) 468 457 rs.first() 469 if rs.getInt(1) >= count:470 self.logger.errorPair(str(stage_id) + " has failed %d times" % count, "skipping")458 if rs.getInt(1) >= self.MAX_FAILS: 459 self.logger.errorPair(str(stage_id) + " has failed %d times" % self.MAX_FAILS, "skipping") 471 460 return True 472 461 else: … … 475 464 self.logger.exception("Unable to check whether this batch has consistently failed") 476 465 466 ''' 467 Returns a list of stage_ids that have failed the max number of times 468 ''' 469 def getConsistentlyFailedIDs(self, batchType, epoch, dvoGpc1Label): 470 471 sql = "SELECT DISTINCT stage_id, COUNT(stage_id) AS numoccur \ 472 FROM batch \ 473 WHERE batch_type = '" + batchType + "' \ 474 AND timestamp > '" + epoch + "' \ 475 AND dvo_db = '" + dvoGpc1Label + "' \ 476 AND processed = -1 \ 477 GROUP BY stage_id HAVING numoccur >= " + str(self.MAX_FAILS) 478 479 ids = [] 480 try: 481 rs = self.executeQuery(sql) 482 while (rs.next()): 483 ids.append(rs.getInt(1)) 484 except: 485 self.logger.exception("Can't query for consistantly failed ids in ipptopsps Db") 486 487 rs.close() 488 489 self.logger.debug("Found %d consistantly failed stage_ids for batch type='%s'" % (len(ids), batchType)) 490 491 return ids 492 493 ''' 494 Locks the batch table. This will wait if the lock is held by someone else 495 ''' 496 def lockBatchTable(self): 497 self.lockTable("batch") 498 499 ''' 500 Creates a new batch. This is done with a locked table in order that no two clients can start work on the same item 501 ''' 502 def createNewBatch(self, batchType, stageID, survey, epoch, dvoDb, datastoreProduct, force): 503 504 batchID = -1; 505 506 if force or \ 507 (not self.alreadyProcessed(batchType, stageID, epoch, dvoDb) \ 508 and not self.processingNow(batchType, stageID, epoch, dvoDb) \ 509 and not self.consistentlyFailed(batchType, stageID, epoch, dvoDb)): 510 511 sql = "INSERT INTO batch ( \ 512 batch_type, \ 513 stage_id, \ 514 survey, \ 515 dvo_db, \ 516 datastore_product \ 517 ) VALUES ( \ 518 '" + batchType + "', \ 519 " + str(stageID) + ", \ 520 '" + survey + "', \ 521 '" + dvoDb + "', \ 522 '" + datastoreProduct + "' \ 523 )" 524 525 self.execute(sql) 526 527 sql = "SELECT MAX(batch_id) FROM batch" 528 529 try: 530 rs = self.executeQuery(sql) 531 rs.first() 532 batchID = rs.getInt(1) 533 self.logger.debug("Created new batch in ippToPsps database with batchID = %d" % batchID) 534 except: 535 self.logger.exception("Unable to get batch ID") 536 batchID = -1 537 538 return batchID; 477 539 478 540
Note:
See TracChangeset
for help on using the changeset viewer.
