Go to the documentation of this file.00001
00002 from crabWrap import crabStatus,convertStatus,getOutput
00003 import os,time
00004 from threading import Thread,Lock,Event
00005
00006 class CrabWatch(Thread):
00007
00008
00009
00010 def __init__(self, project, action = getOutput):
00011 Thread.__init__(self)
00012 self.project = project
00013 self.action = action
00014 self.threshold = 100.0
00015
00016 self.lock = Lock()
00017 self.finish = Event()
00018
00019 def setThreshold(self,threshold):
00020 self.threshold = float(threshold)
00021
00022 def run(self):
00023 exit = False
00024 while not exit:
00025
00026 status = crabStatus(self.project)
00027 statusNew = convertStatus(status)
00028 print "Relative percentage finished: %.0f%%" % statusNew['Finished']
00029 print "Relative percentage failed : %.0f%%" % statusNew['Failed']
00030 print "Relative percentage running : %.0f%%" % statusNew['Running']
00031 if statusNew['Failed'] > 50.0: raise RuntimeError,'Too many jobs have failed (%.0f%%).' % statusNew['Failed']
00032 if statusNew['Finished'] >= self.threshold: break
00033
00034 self.lock.acquire()
00035 if self.finish.isSet(): exit = True
00036 self.lock.release()
00037
00038 if not exit: time.sleep(180)
00039
00040 print "Finished..."
00041
00042 if self.action: self.action(self.project)
00043
00044 if __name__ == '__main__':
00045
00046 project = None
00047 import sys
00048 for opt in sys.argv:
00049 if opt[:8] == 'project=':
00050 project = opt[8:]
00051
00052 if not project: raise ValueError,'Need to set project'
00053
00054 crab = CrabWatch(project)
00055 crab.start()