Exemplo n.º 1
0
 def run(self):
     logger.info('KejiThread start, will do %d times'%(Times))
     #logger.info('I upgrade keji: ' + ' '.join(Kid_List))
     if Delay_Time > 0:
         logger.info('I will start keji at ' + util.next_time(Delay_Time))
         time.sleep(Delay_Time)
     inteval = 30
     ci = 1
     if Times > 0:
         while ci <= Times:
             for i in range(len(Kid_List)):
                 self.do_keji(Kid_List[i])
                 if i < len(Kid_List) - 1:
                     time.sleep(inteval)
             if ci == Times:
                 break
             logger.info('sleeping %d seconds in %d time'%(Sleep_Time, ci))
             logger.info('next round will at ' + util.next_time(Sleep_Time))
             ci += 1
             time.sleep(Sleep_Time)
     else:
         while True:
             # get general info
             gi = GeneralInfo()
             ki = KejiInfo()
             next_keji_cd = gi.get_next_keji_CDTime()
             stime = gi.get_serverTime()
             next_kname = self.get_next_kname(gi, ki)
             sp = 0
             if not next_kname:
                 logger.info('I will send notify at server time: ' + util.next_time(gi.get_next_keji_CDTime() - gi.get_serverTime()))
                 time.sleep(gi.get_next_keji_CDTime() - gi.get_serverTime())
                 logger.info('All keji has upgraded to max level, will exit')
                 util.notify('All keji has upgraded to max level')
                 break
             if next_keji_cd > stime:
                 sp = next_keji_cd - stime + 1
             if sp > 0:
                 logger.info('I will start upgrade %s at %s'%(next_kname, util.next_time(sp)))
                 time.sleep(sp)
             else:
                 logger.info('I will start upgrade %s now'%(next_kname))
             res = self.do_keji(next_kname)
             if res.has_key('exception'):
                 msg = res['exception']['message']
                 logger.error('Got Exception "%s", will exit'%(msg))
                 if msg == 'CDTimeNotCool':
                     continue
                 return
             time.sleep(2)