IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33487 for trunk/ippToPsps


Ignore:
Timestamp:
Mar 13, 2012, 9:48:05 AM (14 years ago)
Author:
rhenders
Message:

now deletes an item from the pending table once started working on it; now pauses if no stripes are available after 2 attemps; Dvo object no created in constructor and scratch Db only changed if necessary; changes to way IN batches are handled; using new argument in base-class printUsage() method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/loader.py

    r33346 r33487  
    4949        if not self.scratchDb.connected:
    5050            self.logger.errorPair("Cannot connect to a", "scratch database")
    51             raise Exception("No scratch Db")
     51            exitProgram("no available scratch database")
    5252       
    5353        # now pass scratch Db to dvo object
     54        self.dvo = Dvo(self.logger, self.config)
    5455        self.dvo.setScratchDb(self.scratchDb.dbName)
    5556
    5657        # if an IN batch is requested, create and quit
    5758        if len(sys.argv) > 2 and sys.argv[2] == "init":
    58            batchID = self.ippToPspsDb.createNewBatch("IN", 0, self.config)
     59           batchID = self.ippToPspsDb.createNewBatch("IN", 0)
    5960           if batchID > 0:
    6061               batch = InitBatch(self.logger,
     
    6566                       batchID)
    6667               batch.run()
    67    
     68           else:
     69               self.logger.errorPair("Could not create batch ID", "%d" % batchID)
     70               self.exitProgram("failed to create init batch")
     71               
    6872           self.exitProgram("init batch created")
    6973   
     
    8084
    8185        ret = super(Loader, self).refreshConfig()
    82         self.dvo = Dvo(self.logger, self.config)
     86       
    8387        try: self.dvo.setScratchDb(self.scratchDb.dbName)
    8488        except: pass
     
    9296    def run(self):
    9397
     98        numAttempts = 0
    9499        while True:
    95100
    96             boxIds = self.ippToPspsDb.getBoxIds(self.config.name)
    97    
    98             self.logger.infoPair("Boxes with unprocessed data", "%d" % len(boxIds))
    99 
    100             for boxId in boxIds:
    101      
    102                 self.checkClientStatus()
    103 
    104                 # get box info. if boxes have changed, break and start again
    105                 try:
    106                     boxDim = self.ippToPspsDb.getBoxDimensions(boxId)
    107                 except:
    108                    self.logger.infoPair("Can't get details for this box", "%d" % boxId)
    109                    break
    110                  
    111                 for batchType in self.config.batchTypes:
    112                    
    113                     ids = self.ippToPspsDb.getPendingIds(boxId, batchType)
    114            
     101            for batchType in self.config.batchTypes:
     102
     103                # get a stripe's worth of box IDs
     104                boxIds = self.ippToPspsDb.getStripeBoxIds(self.HOST, self.PID, batchType)
     105
     106                numAttempts += 1
     107
     108                self.logger.infoPair("Boxes with unprocessed data", "%d" % len(boxIds))
     109   
     110                if len(boxIds) > 0: numAttempts = 0
     111
     112                for boxId in boxIds:
     113         
     114                    self.checkClientStatus()
     115   
     116                    # get box info. if boxes have changed, break and start again
     117                    try:
     118                        boxDim = self.ippToPspsDb.getBoxDimensions(boxId)
     119                    except:
     120                       self.logger.infoPair("Can't get details for this box", "%d" % boxId)
     121                       break
     122     
     123                    ids = self.ippToPspsDb.getPendingIdsForThisBox(boxId, batchType)
     124               
    115125                    if len(ids) < 1:
    116126                        self.logger.debugPair("No " + batchType + " items found in this box", "skipping")
    117127                        continue
    118            
     128               
    119129                    self.logger.infoSeparator()
     130                    self.logger.infoTitle("New box")
    120131                    self.logger.infoPair("Box dimensions", "%.1f / %.1f / %.1f" % (boxDim['RA'], boxDim['DEC'], boxDim['SIDE']))
    121132                    self.logger.infoPair(batchType + " items found in this box", "%d" % len(ids))
    122133                    boxSizeWithBorder = boxDim['SIDE'] + (self.config.BORDER * 2)
    123    
     134      
    124135                    # look in DVO for this box (with extra border)
    125136                    self.dvo.setSkyAreaAsBox(boxDim['RA'], boxDim['DEC'], boxSizeWithBorder)
     
    138149                        useFullTables = 1
    139150                    else: useFullTables = 0
    140            
     151               
    141152                    self.logger.infoBool("Using pre-ingested DVO data?", useFullTables)
    142153                    self.processTheseItems(batchType, ids, useFullTables)
    143154
    144155            self.checkClientStatus()
    145             if not self.waitForPollTime(): break
     156            if numAttempts > 1 and not self.waitForPollTime(): break
    146157
    147158       
     
    158169        for id in ids:
    159170   
    160             batchID = self.ippToPspsDb.createNewBatch(batchType, id, self.config)
     171            batchID = self.ippToPspsDb.createNewBatch(batchType, id)
    161172           
    162173            if batchID < 0:
     
    165176   
    166177            self.ippToPspsDb.unlockTables()
    167    
     178   
     179            self.ippToPspsDb.deletePendingItem(batchType, id)
     180
    168181            if batchType == "P2":
    169182                batch = DetectionBatch(self.logger,
     
    194207            self.logger.infoSeparator()
    195208   
    196             # if in test mode, then quit after one batch
     209            # if in test mode, then quit after one batch # TODO remove
    197210            if self.config.test: break
    198211   
     
    204217    '''
    205218    def printUsage(self):
    206         super(Cleanup, self).printUsage()
    207         print " [init]"
     219        super(Cleanup, self).printUsage("<[init]>")
    208220
    209221   
     
    217229except Exception, e:
    218230    print str(e)
    219     traceback.print_exc() 
     231    traceback.print_exc()
Note: See TracChangeset for help on using the changeset viewer.