def _mainloop(self): """ The main loop of scheduler """ self.logger.debug("Looking for new commands") try : self.rn_stats() self.wt_stats() self.logger.debug("Number of tracked/stopped circuits: %d" % len(self.stopped_track)) if self.lock_start.locked: self.logger.info("Previous batch not finished, skiping") return True if self.has_free_slots(): top = self.free_slots if top > 0 : starting_ids = [c.id for c in self.circuits if not c.is_running] running_ids = [c.id for c in self.circuits if c.initialized] waiting_ids = [c.id for c in self.get_valid_waitings()] ids_to_exclude = running_ids + waiting_ids + starting_ids # Looking for new commands ids = get_ids_to_start(self.config.name, ids_to_exclude, top) if len(ids) > 0 : self.logger.info("Prepare %d new commands to initialize" % len(ids)) else : self.logger.debug("Nothing to initialize") return True # starting of all ids will be locked until the start # of last circuit launching dstart = self.lock_start.run(self.start_all, ids) @dstart.addCallback def _cb(reason): self.logger.info("Batch completed, ready for next.") @dstart.addErrback def _eb(reason): self.logger.info("Start batch failed! : %s" % reason) else : self.logger.info("Slots will be filled with by waiting circuits") else : self.logger.info("Slots full: continue and waiting on next awake") return True except Exception, e: self.logger.error("Mainloop execution failed: %s" % str(e)) return True
def _mainloop(self): """ The main loop of scheduler """ self.logger.debug("Looking for new commands") try : self.rn_stats() self.wt_stats() self.logger.debug("Number of tracked/stopped circuits: %d" % len(self.stopped_track)) if self.has_free_slots() : top = self.free_slots * 2 if top > 0 : starting_ids = [c.id for c in self.circuits if not c.is_running] running_ids = [c.id for c in self.circuits if c.initialized] waiting_ids = [c.id for c in self.get_valid_waitings()] ids_to_exclude = running_ids + waiting_ids + starting_ids ids = get_ids_to_start(self.config.name, ids_to_exclude, top) if len(ids) > 0 : self.logger.info("Prepare %d new commands to initialize" % len(ids)) else : self.logger.debug("Nothing to initialize") return True self.start_all(ids) else : self.logger.info("Slots will be filled with by waiting circuits") else : self.logger.info("Slots full: continue and waiting on next awake") return True except Exception, e: self.logger.error("Mainloop execution failed: %s" % str(e)) return True