def sync_foreground(repo_id): taskapi = TaskAPI() repoapi = RepositoryAPI() running = repoapi.running_task(repoapi.sync_list(repo_id)) if running is not None: raise Exception("Sync for repository %s already in progress" % repo_id) task = repoapi.sync(repo_id) while not task_end(task): time.sleep(1) task = taskapi.info(task["id"]) if not task_succeeded(task): if task["exception"] and task["traceback"]: raise Exception(task["traceback"][-1]) elif task["exception"]: raise Exception("Unknown sync error: %s" % task["exception"]) else: raise Exception("Unknown sync error") return task
def run(self, repo_id): taskapi = TaskAPI() repoapi = RepositoryAPI() running = repoapi.running_task(repoapi.sync_list(repo_id)) if running is not None: raise TaskExecutionError("Metadata rebuild for repository %s " "already in progress" % repo_id) task = repoapi.sync(repo_id) while not task_end(task): time.sleep(1) task = taskapi.info(task['id']) if not task_succeeded(task): if task['exception'] and task['traceback']: raise TaskExecutionError(task['traceback'][-1]) elif task['exception']: raise TaskExecutionError("Unknown metadata rebuild error: %s" % task['exception']) else: raise TaskExecutionError("Unknown metadata rebuild error") return "Metadata rebuilt for %s" % repo_id