Ejemplo n.º 1
0
class Polling(threading.Thread):
    
    running = False
    
    def __init__(self, project=None):
        super(Polling, self).__init__()
        self.project = project
        self.daemon = True
        self.logger = settings.get_logger(settings.LOG, self.__class__.__name__)
        self.memory = MemoryMonitor()
    
    def run(self):
        self.running = True
        self.init_memory = self.memory.usage()
        self.logger.debug("Init Memory: %s" % self.init_memory)
        while self.running:
            try:
                self.start_memory = self.memory.usage()
                polls = self.get_polls()
                if polls:
                    #print polls.count()
                    self.logger.debug("Running %s polls" % polls.count())
                    for p in polls: p.start()
            except Exception as e:
                print e
                self.logger.exception(e)
            self.end_memory = self.memory.usage()
            self.logger.debug("Current Threads: %s" % threading.active_count())
            self.logger.debug("Current Memory: %s" % self.end_memory)
            time.sleep(1)
            
    def get_polls(self):
        try:
            now = datetime.datetime.utcnow()
            qu = {'status':Poll.IDLE, "next":{"$lte":now}, 'project':self.project}
            polls = Poll.find(query=qu)
            return polls
        except Exception as e:
            self.logger.exception(e)
Ejemplo n.º 2
0
 def __init__(self, project=None):
     super(Polling, self).__init__()
     self.project = project
     self.daemon = True
     self.logger = settings.get_logger(settings.LOG, self.__class__.__name__)
     self.memory = MemoryMonitor()