From 807add1e074a408edf2365405062e3d9c6a49556 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 2 Jun 2016 21:54:15 +0100 Subject: Support enabling/disabling various parts of the update process. Add a generic handler for collecting results of jobs. Count the failures of jobs and use it as the return value. --- gentoobrowse-api/util/update.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/gentoobrowse-api/util/update.cpp b/gentoobrowse-api/util/update.cpp index bc0082d..01fb263 100644 --- a/gentoobrowse-api/util/update.cpp +++ b/gentoobrowse-api/util/update.cpp @@ -8,11 +8,13 @@ int main(int c, char ** v) { std::string endpoint; - bool background; + bool background, tree, bugs; po::options_description opts("Gentoo Browse Util::Update options"); opts.add_options() ("endpoint", po::value(&endpoint)->default_value("tcp -p 9001"), "Service endpoint") ("background,b", po::value(&background)->default_value(false)->zero_tokens(), "Background") + ("bugs", po::value(&bugs)->default_value(true), "Update bugs") + ("tree", po::value(&tree)->default_value(true), "Update tree") ("help,h", "Show help") ; @@ -29,17 +31,28 @@ main(int c, char ** v) auto m = Gentoo::MaintenancePrx::checkedCast(ic->stringToProxy("maintenance:" + endpoint)); m->ice_ping(); - auto rpt = m->begin_refreshPackageTree(); - auto rb = m->begin_refreshBugs(); - rpt->waitForSent(); - rb->waitForSent(); + std::set jobs; + if (tree) jobs.insert(m->begin_refreshPackageTree()); + if (bugs) jobs.insert(m->begin_refreshBugs()); + std::for_each(jobs.begin(), jobs.end(), [](const auto & j) { j->waitForSent(); }); + + int failures = 0; if (!background) { - m->end_refreshPackageTree(rpt); - m->end_refreshBugs(rb); + std::for_each(jobs.begin(), jobs.end(), [&failures](const auto & j) { + try { + j->waitForCompleted(); + j->throwLocalException(); + } + catch (const std::exception & ex) { + failures += 1; + std::cerr << ex.what() << std::endl; + } + }); } + jobs.clear(); ic->destroy(); - return 0; + return failures; } -- cgit v1.2.3