Пример #1
0
class Manager(Thread):
    def __init__(self, app):
        Thread.__init__(self)
        self.must_run = False
        self.app = app
        self.build_list = {}
        self.carrier = Carrier(pecan.conf.rabbit_server,
                               pecan.conf.rabbit_port, pecan.conf.rabbit_user,
                               pecan.conf.rabbit_password,
                               pecan.conf.rabbit_vhost, pecan.conf.rabbit_db)
        self.supported_build_type = pecan.conf.supported_build_type
        for build_type in self.supported_build_type:
            self.carrier.declare_queue('%s.queue' % build_type)

        self.logger = None

    def shutdown(self):
        logging.debug("Stopping Manager")
        self.carrier.closing = True
        self.must_run = False

    def run(self):
        self.must_run = True
        logging.debug("Starting Manager")

        while self.must_run:
            time.sleep(0.1)
            for build_type in self.supported_build_type:
                new_build = self.carrier.get_message('%s.queue' % build_type)

                build = None
                if new_build is not None:
                    distro_name = new_build['distro_name']
                    build_conf = new_build['build_conf']
                    root_folder = new_build['root_folder']
                    build_path = new_build['build_path']
                    build = Build(new_build['build'])
                    job_id = new_build['job_id']
                    path = os.path.dirname(get_logger_path(build))
                    try:
                        os.makedirs(path)
                    except Exception:
                        pass
                    self.logger = get_logger(build, distro_name)
                    self.logger.debug(build.dumps())
                    builder_class = globals().get(build_type.title() +
                                                  'Builder')
                    builder = builder_class(distro_name, build_conf,
                                            root_folder, self.logger, build,
                                            build_path, job_id)
                    builder.run()
                    """
                    build = Build(new_build)
                    build.user = User.fetch(new_build['username'],
                                            sub_objects=False)
                    build.project = Project.fetch(build.user,
                                                  new_build['project_name'],
                                                  sub_objects=False)
                    """
                """if build:
Пример #2
0
class Manager(Thread):
    def __init__(self, app):
        Thread.__init__(self)
        self.must_run = False
        self.app = app
        self.build_list = {}
        self.carrier = Carrier(
            pecan.conf.rabbit_server,
            pecan.conf.rabbit_port,
            pecan.conf.rabbit_user,
            pecan.conf.rabbit_password,
            pecan.conf.rabbit_vhost,
            pecan.conf.rabbit_db
        )
        self.supported_build_type = pecan.conf.supported_build_type
        for build_type in self.supported_build_type:
            self.carrier.declare_queue('%s.queue' % build_type)

        self.logger = None

    def shutdown(self):
        logging.debug("Stopping Manager")
        self.carrier.closing = True
        self.must_run = False

    def run(self):
        self.must_run = True
        logging.debug("Starting Manager")

        while self.must_run:
            time.sleep(0.1)
            for build_type in self.supported_build_type:
                new_build = self.carrier.get_message('%s.queue' % build_type)

                build = None
                if new_build is not None:
                    distro_name = new_build['distro_name']
                    build_conf = new_build['build_conf']
                    root_folder = new_build['root_folder']
                    build_path = new_build['build_path']
                    build = Build(new_build['build'])
                    path = os.path.dirname(get_logger_path(build))
                    try:
                        os.makedirs(path)
                    except Exception:
                        pass
                    self.logger = get_logger(build, distro_name)
                    self.logger.debug(build.dumps())
                    builder_class = globals().get(build_type.title() + 'Builder')
                    builder = builder_class(distro_name, build_conf, root_folder, self.logger, build, build_path)
                    builder.run()
                    """
                    build = Build(new_build)
                    build.user = User.fetch(new_build['username'],
                                            sub_objects=False)
                    build.project = Project.fetch(build.user,
                                                  new_build['project_name'],
                                                  sub_objects=False)
                    """
                """if build:
Пример #3
0
class Manager(object):
    def __init__(self, app):
        self.must_run = False
        self.app = app
        self.build_list = {}
        self.carrier = Carrier(pecan.conf.rabbit_server,
                               pecan.conf.rabbit_port, pecan.conf.rabbit_user,
                               pecan.conf.rabbit_password,
                               pecan.conf.rabbit_vhost, pecan.conf.rabbit_db)
        self.carrier.declare_queue('builds.queue')

    def shutdown(self):
        logging.debug("Stopping Manager")
        self.carrier.closing = True
        self.must_run = False

    def run(self):
        self.must_run = True
        logging.debug("Starting Manager")

        while self.must_run:
            time.sleep(0.1)
            new_build = self.carrier.get_message('builds.queue')
            build = None
            if new_build is not None:
                build = Build(new_build)
                if build:
                    build.user = User.fetch(new_build['username'],
                                            sub_objects=False)
                    build.project = Project.fetch(build.username,
                                                  new_build['project_name'],
                                                  sub_objects=False)
                    logging.debug("Task received")
                    build.set_status("dispatching")
                    dispatcher = Dispatcher(build)
                    self.build_list[dispatcher.uuid2] = dispatcher
                    dispatcher.start()

            self.check_builds_status()

    def check_builds_status(self):
        builds = mongo.builds.find(
            {"status": {
                "$nin": ["succeeded", "failed"]
            }})
        for b in builds:
            finished = 0
            build = Build(b)
            jobs = build.get_jobs()

            if len(jobs) == build.job_count and build.job_count > 0:
                for job in jobs:
                    if job.status in ['succeeded', 'failed']:
                        finished += 1

                if finished == len(jobs):
                    if all([
                            True if j.status == 'succeeded' else False
                            for j in jobs
                    ]):
                        build.set_status('succeeded')
                    else:
                        build.set_status('failed')
                    build.finishing()

        # collect old jammed build
        time_limit = time.time() - pecan.conf.build_lifetime
        builds = mongo.builds.find({
            "status": {
                "$nin": ["succeeded", "failed"]
            },
            "created": {
                "$lte": time_limit
            }
        })
        for b in builds:
            build = Build(b)
            build.set_status('failed')
            build.finishing()
            jobs = build.get_jobs()
            for job in jobs:
                if job.status not in ['succeeded', 'failed']:
                    job.set_status('failed')