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)): log.info("starting updater thread {}".format(i)) worker = Worker(location, "update", self.update_queue) worker.start() workers.append(worker) while True: outdated_target = self.database.get_outdated_target() if outdated_target: log.info("found outdated target %s", outdated_target) self.update_queue.put(outdated_target) else: time.sleep(5)
class Boss(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.log = logging.getLogger(__name__) self.config = Config() self.database = Database(self.config) self.build_queue = Queue(1) def run(self): workers = [] for worker_location in self.config.get("worker", []): worker = Worker(worker_location, "image", self.build_queue) worker.start() workers.append(worker) self.log.info("Active workers are %s", workers) while True: build_job = self.database.get_build_job() if build_job: self.log.info("Found build job %s", build_job) self.build_queue.put(build_job) else: time.sleep(10)