Ejemplo n.º 1
0
class Updater(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.log = logging.getLogger(__name__)
        self.config = Config()
        self.database = Database(self.config)
        self.update_queue = Queue(1)

    def run(self):
        location = self.config.get("updater_dir", "updater")
        Worker(location, None, None).setup_meta()
        workers = []

        # start all workers
        for i in range(0, self.config.get("updater_threads", 4)):
            worker = Worker(location, "update", self.update_queue)
            worker.start()
            workers.append(worker)

        while True:
            outdated_subtarget = self.database.get_subtarget_outdated()
            if outdated_subtarget:
                log.info("found outdated subtarget %s", outdated_subtarget)
                self.update_queue.put(outdated_subtarget)
            else:
                time.sleep(5)
class Updater(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.log = logging.getLogger(__name__)
        self.log.info("log initialized")
        self.config = Config()
        self.log.info("config initialized")
        self.db = Database(self.config)
        self.log.info("db initialized")

    def run(self):
        self.log.info("run updater")
        while True:
            outdated_subtarget = self.db.get_subtarget_outdated()

            if not outdated_subtarget:
                self.log.debug("updater sleeping")
                time.sleep(60)
            else:
                self.log.info("found outdated_subtarget %s",
                              outdated_subtarget)
                distro, release, target, subtarget = outdated_subtarget
                imagebuilder = ImageBuilder(distro, str(release), target,
                                            subtarget)
                self.log.info("initializing imagebuilder")
                if not imagebuilder.created():
                    self.log.info("setup imagebuilder")
                    imagebuilder.run()
                    self.log.info("parse profiles/default packages")

                info = imagebuilder.parse_info()
                if info:
                    self.db.insert_profiles(distro, release, target, subtarget,
                                            *info)
                else:
                    logging.error("could not receive profiles of %s/%s",
                                  target, subtarget)
                    self.db.subtarget_synced(distro, release, target,
                                             subtarget)
                    continue
                    #exit(1)

                self.log.info("parse packages")
                packages = imagebuilder.parse_packages()
                self.db.insert_packages_available(distro, release, target,
                                                  subtarget, packages)
                self.db.subtarget_synced(distro, release, target, subtarget)