def update_finished_jobs(self):
        # Remove the node_id from all finished nodes
        keep_failed = Configuration().get_int("KEEP_FAILED")
        keep_failed_timeout = Configuration().get_int("KEEP_FAILED_TIMEOUT")
        earliest_failed = time_services.time() - keep_failed_timeout

        with self.jobQueue.db.get_session() as session:
            finished_node_jobs = session.query(Job).filter(
                and_(Job.state.in_([constants.COLLECTED, constants.FINISHED, constants.OBSOLETE]), Job.node_id != 0)
            )

            # Construct a list of all jobs that could be kept because they failed
            keep_jobs = []
            if keep_failed > 0:
                for job in finished_node_jobs:
                    if job.result == "Failed":
                        updated = time.mktime(job.updated.timetuple())
                        if updated < earliest_failed:
                            self.log.debug("Not keeping %s; too old", job)
                            continue
                        keep_jobs.append(job)
                # Only keep the <KEEP_FAILED> most recent failures
                keep_jobs.sort(key=lambda x: x.updated)
                self.log.debug("Keeping %s, discarding %s", keep_jobs[-keep_failed:], keep_jobs[:-keep_failed])
                keep_jobs = keep_jobs[-keep_failed:]

            for job in finished_node_jobs:
                if job in keep_jobs:
                    continue
                job.update(self.jobQueue.db, node_id=0)
    def update_finished_jobs(self):
        # Remove the node_id from all finished nodes
        keep_failed = Configuration().get_int('KEEP_FAILED')
        keep_failed_timeout = Configuration().get_int('KEEP_FAILED_TIMEOUT')
        earliest_failed = time_services.time() - keep_failed_timeout

        with self.jobQueue.db.get_session() as session:
            finished_node_jobs = session.query(Job).filter(
                and_(
                    Job.state.in_([
                        constants.COLLECTED, constants.FINISHED,
                        constants.OBSOLETE
                    ]), Job.node_id != 0))

            # Construct a list of all jobs that could be kept because they failed
            keep_jobs = []
            if keep_failed > 0:
                for job in finished_node_jobs:
                    if job.result == 'Failed':
                        updated = time.mktime(job.updated.timetuple())
                        if updated < earliest_failed:
                            self.log.debug('Not keeping %s; too old', job)
                            continue
                        keep_jobs.append(job)
                # Only keep the <KEEP_FAILED> most recent failures
                keep_jobs.sort(key=lambda x: x.updated)
                self.log.debug('Keeping %s, discarding %s',
                               keep_jobs[-keep_failed:],
                               keep_jobs[:-keep_failed])
                keep_jobs = keep_jobs[-keep_failed:]

            for job in finished_node_jobs:
                if job in keep_jobs:
                    continue
                job.update(self.jobQueue.db, node_id=0)
Beispiel #3
0
 def addNode(self, id, ip, state):
     node = mock.Mock()
     node.id = id
     node.ip = ip
     node.state = state
     node.state_time = time_services.time()
     node.label_name = self.image
     self.nodes.append(node)
 def addNode(self, id, ip, state):
     node = mock.Mock()
     node.id = id
     node.ip = ip
     node.state = state
     node.state_time = time_services.time()
     node.label_name = self.image
     self.nodes.append(node)
Beispiel #5
0
 def getHeldNodes(self, min_state_age=300):
     heldNodes = set()
     oldStateTime = int(time_services.time()) - min_state_age
     with self.getSession() as session:
         for node in session.getNodes():
             if node.state != self.nodedb.HOLD:
                 continue
             if node.state_time >= oldStateTime:
                 continue
             heldNodes.add(node.id)
     return heldNodes