diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-06-02 21:54:15 +0100 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-06-02 21:54:15 +0100 | 
| commit | 807add1e074a408edf2365405062e3d9c6a49556 (patch) | |
| tree | 5375bd059e59eab4afa2ac3d04f3d035952283d7 | |
| parent | No need to expose stuff publically for testing if we just compile them into t... (diff) | |
| download | gentoobrowse-api-807add1e074a408edf2365405062e3d9c6a49556.tar.bz2 gentoobrowse-api-807add1e074a408edf2365405062e3d9c6a49556.tar.xz gentoobrowse-api-807add1e074a408edf2365405062e3d9c6a49556.zip | |
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.
| -rw-r--r-- | gentoobrowse-api/util/update.cpp | 29 | 
1 files 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<Ice::AsyncResultPtr> 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;  } | 
