def handle_hook(): """ :param first: :param last: :return: """ saved_status = False if not status.idle and 'Idle' not in status.current_status: saved_status = status.current_status else: status.idle = False package_queue = status.queue hook_q = status.hook_queue status.current_status = 'Build hook was triggered. Checking docker images.' if not status.iso_flag: image = docker_utils.maybe_build_base_devel() else: status.iso_flag = False image = docker_utils.maybe_build_mkarchiso() if not image: if not saved_status: status.idle = True status.current_status = 'Idle' else: status.current_status = saved_status return False logger.info('Processing packages.') status.current_status = 'Processing packages.' all_deps = process_package_queue() logger.info('All queued packages are in the database, checking deps to determine build order.') status.current_status = 'Determining build order based on package dependencies.' if len(all_deps) > 1: topsort = check_deps(all_deps) logger.info('Check deps complete. Starting build_pkgs') status.current_status = 'Check deps complete. Starting build container.' for p in topsort: hook_q.remove(p) if p not in package_queue: package_queue.append(p) build_queue.enqueue_call(build_pkg_handler, timeout=84600) elif len(all_deps) == 1: p = hook_q.lpop() if p not in package_queue: package_queue.append(p) build_queue.enqueue_call(build_pkg_handler, timeout=84600) if saved_status and not status.idle: status.current_status = saved_status
def handle_hook(first=False, last=False): status.idle = False pull_from = 'antergos' packages = status.queue() if os.path.exists(REPO_DIR): remove(REPO_DIR) try: subprocess.check_call( ['git', 'clone', 'http://github.com/antergos/antergos-packages.git'], cwd='/opt') subprocess.check_call(['chmod', '-R', 'a+rw', REPO_DIR], cwd='/opt') except subprocess.CalledProcessError as err: logger.error(err) if status.iso_flag: status.iso_flag = False status.current_status = 'Building docker image.' status.iso_building = True image = docker_utils.maybe_build_mkarchiso() db.lrem('queue', 0, 'antergos-iso') db.lrem('queue', 0, 'antergos-iso.openbox') if image: archs = ['x86_64', 'i686'] if db.get('isoMinimal') == 'True': iso_name = 'antergos-iso-minimal-' else: iso_name = 'antergos-iso-' for arch in archs: db.rpush('queue', iso_name + arch) version = datetime.datetime.now().strftime('%Y.%m.%d') pkgobj = package.get_pkg_object(iso_name + arch) pkgobj.save_to_db('version', version) build_iso() db.set('isoBuilding', 'False') db.set('isoMinimal', 'False') db.set('idle', "True") return True elif first and not status.iso_flag: status.current_status = 'Building docker image.' image = docker_utils.maybe_build_base_devel() if not image: return False logger.info('Checking database for packages.') status.current_status = 'Checking database for queued packages' all_deps = process_package_queue(packages) logger.info('All queued packages are in the database, checking deps to determine build order.') status.current_status = 'Determining build order by sorting package depends' if len(all_deps) > 1: topsort = check_deps(all_deps) check = [] packages.delete() for p in topsort: # TODO: What if there is already a group of packages in queue prior to the current group? packages.append(p) logger.info('Check deps complete. Starting build_pkgs') logger.debug((packages, status.iso_flag)) status.current_status = 'Check deps complete. Starting build container.' if not status.iso_flag and len(packages) > 0: pack = status.queue().lpop() if pack and pack is not None and pack != '': pkgobj = package.get_pkg_object(name=pack) else: return False rqjob = get_current_job(db) rqjob.meta['is_first'] = first rqjob.meta['is_last'] = last rqjob.meta['package'] = pkgobj.name rqjob.save() status.now_building = pkgobj.name built = build_pkgs(last, pkgobj) # TODO: Move this into its own method if built: completed = status.completed() failed = status.failed() blds = pkgobj.builds() total = len(blds) if total > 0: success = len([x for x in pkgobj.blds if x in completed]) failure = len([x for x in pkgobj.blds if x in failed]) if success > 0: success = 100 * success / total else: success = 0 if failure > 0: failure = 100 * failure / total else: failure = 0 pkgobj.success_rate = success pkgobj.failure_rate = failure if last: remove('/opt/antergos-packages') status.idle = True status.building = 'Idle' status.now_building = 'Idle' status.container = '' status.building_num = '' status.building_start = '' logger.info('All builds completed.')