-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (49 loc) · 1.5 KB
/
main.cpp
File metadata and controls
58 lines (49 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "BuildStatus.h"
#include "ProgramOptions.h"
#include "BuildStatusReporter.h"
#include <string>
#include <iostream>
#include <exception>
#include <chrono>
#include <thread>
#include <vector>
#include <algorithm>
#include <iterator>
#include <numeric>
using namespace std;
using namespace std::chrono;
using namespace boost::program_options;
namespace {
void runBuildStatusLoop(BuildStatusReporter& reporter, const vector<string>& statusUris, seconds pollingPeriod)
{
vector<BuildStatus> statuses;
while (true) {
statuses.clear();
try {
transform(begin(statusUris), end(statusUris), back_inserter(statuses), queryLastBuildStatus);
} catch (exception& ex) {
cerr << "Failed to get build status. Error = " << ex.what() << endl;
}
const BuildStatus initialStatus = { BuildStatus::unknown, false };
BuildStatus aggregateStatus = accumulate(begin(statuses), end(statuses), initialStatus, combineBuildStatus);
reporter.reportBuildStatus(aggregateStatus);
this_thread::sleep_for(pollingPeriod);
}
}
}
int main(int argc, char* argv[])
{
try {
ProgramOptions opts(argc, argv);
runBuildStatusLoop(opts.getReporter(), opts.getStatusUris(), opts.getPollingPeriod());
} catch(boost::program_options::error& ex) {
cerr << "Commandline error: " << ex.what() << endl;
return 1;
} catch (exception& ex) {
cerr << "Exception unwound to main. Details: " << ex.what() << endl;
throw;
} catch(...) {
cerr << "Unknown exception unwound to main." << endl;
throw;
}
}