mirror of
https://github.com/ohwgiles/laminar.git
synced 2024-10-27 20:34:20 +00:00
laminarc: improve exit codes and errors
- return non-zero when failed to connect to laminard - only output trigger links on successful trigger - better error messages Resolves #121
This commit is contained in:
parent
2e54773e83
commit
eadcdbdf9c
@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2015-2018 Oliver Giles
|
/// Copyright 2015-2020 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@ -83,7 +83,16 @@ int main(int argc, char** argv) {
|
|||||||
return EXIT_BAD_ARGUMENT;
|
return EXIT_BAD_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct: public kj::TaskSet::ErrorHandler {
|
||||||
|
void taskFailed(kj::Exception&& e) override {
|
||||||
|
fprintf(stderr, "%s\n", e.getDescription().cStr());
|
||||||
|
ret = EXIT_OPERATION_FAILED;
|
||||||
|
}
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
} errorHandler;
|
||||||
|
kj::TaskSet ts(errorHandler);
|
||||||
|
int& ret = errorHandler.ret;
|
||||||
|
|
||||||
const char* address = getenv("LAMINAR_HOST") ?: getenv("LAMINAR_BIND_RPC") ?: "unix-abstract:laminar";
|
const char* address = getenv("LAMINAR_HOST") ?: getenv("LAMINAR_BIND_RPC") ?: "unix-abstract:laminar";
|
||||||
|
|
||||||
capnp::EzRpcClient client(address);
|
capnp::EzRpcClient client(address);
|
||||||
@ -96,23 +105,20 @@ int main(int argc, char** argv) {
|
|||||||
fprintf(stderr, "Usage %s queue <jobName>\n", argv[0]);
|
fprintf(stderr, "Usage %s queue <jobName>\n", argv[0]);
|
||||||
return EXIT_BAD_ARGUMENT;
|
return EXIT_BAD_ARGUMENT;
|
||||||
}
|
}
|
||||||
kj::Vector<capnp::RemotePromise<LaminarCi::QueueResults>> promises;
|
|
||||||
int jobNameIndex = 2;
|
int jobNameIndex = 2;
|
||||||
// make a request for each job specified on the commandline
|
// make a request for each job specified on the commandline
|
||||||
do {
|
do {
|
||||||
auto req = laminar.queueRequest();
|
auto req = laminar.queueRequest();
|
||||||
req.setJobName(argv[jobNameIndex]);
|
req.setJobName(argv[jobNameIndex]);
|
||||||
int n = setParams(argc - jobNameIndex - 1, &argv[jobNameIndex + 1], req);
|
int n = setParams(argc - jobNameIndex - 1, &argv[jobNameIndex + 1], req);
|
||||||
promises.add(req.send());
|
ts.add(req.send().then([&ret,argv,jobNameIndex](capnp::Response<LaminarCi::QueueResults> resp){
|
||||||
|
if(resp.getResult() != LaminarCi::MethodResult::SUCCESS) {
|
||||||
|
fprintf(stderr, "Failed to queue job '%s'\n", argv[jobNameIndex]);
|
||||||
|
ret = EXIT_OPERATION_FAILED;
|
||||||
|
}
|
||||||
|
}));
|
||||||
jobNameIndex += n + 1;
|
jobNameIndex += n + 1;
|
||||||
} while(jobNameIndex < argc);
|
} while(jobNameIndex < argc);
|
||||||
// pend on the promises
|
|
||||||
for(auto& p : promises) {
|
|
||||||
if(p.wait(waitScope).getResult() != LaminarCi::MethodResult::SUCCESS) {
|
|
||||||
fprintf(stderr, "Failed to queue job '%s'\n", argv[2]);
|
|
||||||
return EXIT_OPERATION_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if(strcmp(argv[1], "start") == 0 || strcmp(argv[1], "trigger") == 0) {
|
} else if(strcmp(argv[1], "start") == 0 || strcmp(argv[1], "trigger") == 0) {
|
||||||
if(strcmp(argv[1], "trigger") == 0)
|
if(strcmp(argv[1], "trigger") == 0)
|
||||||
fprintf(stderr, "Warning: 'trigger' is deprecated, use 'queue' for the old behavior\n");
|
fprintf(stderr, "Warning: 'trigger' is deprecated, use 'queue' for the old behavior\n");
|
||||||
@ -121,10 +127,6 @@ int main(int argc, char** argv) {
|
|||||||
return EXIT_BAD_ARGUMENT;
|
return EXIT_BAD_ARGUMENT;
|
||||||
}
|
}
|
||||||
kj::Vector<capnp::RemotePromise<LaminarCi::StartResults>> promises;
|
kj::Vector<capnp::RemotePromise<LaminarCi::StartResults>> promises;
|
||||||
struct: public kj::TaskSet::ErrorHandler {
|
|
||||||
void taskFailed(kj::Exception&&) override {}
|
|
||||||
} ignoreFailed;
|
|
||||||
kj::TaskSet ts(ignoreFailed);
|
|
||||||
int jobNameIndex = 2;
|
int jobNameIndex = 2;
|
||||||
// make a request for each job specified on the commandline
|
// make a request for each job specified on the commandline
|
||||||
do {
|
do {
|
||||||
@ -135,21 +137,16 @@ int main(int argc, char** argv) {
|
|||||||
if(resp.getResult() != LaminarCi::MethodResult::SUCCESS) {
|
if(resp.getResult() != LaminarCi::MethodResult::SUCCESS) {
|
||||||
fprintf(stderr, "Failed to start job '%s'\n", argv[2]);
|
fprintf(stderr, "Failed to start job '%s'\n", argv[2]);
|
||||||
ret = EXIT_OPERATION_FAILED;
|
ret = EXIT_OPERATION_FAILED;
|
||||||
}
|
} else
|
||||||
printTriggerLink(argv[jobNameIndex], resp.getBuildNum());
|
printTriggerLink(argv[jobNameIndex], resp.getBuildNum());
|
||||||
}));
|
}));
|
||||||
jobNameIndex += n + 1;
|
jobNameIndex += n + 1;
|
||||||
} while(jobNameIndex < argc);
|
} while(jobNameIndex < argc);
|
||||||
ts.onEmpty().wait(waitScope);
|
|
||||||
} else if(strcmp(argv[1], "run") == 0) {
|
} else if(strcmp(argv[1], "run") == 0) {
|
||||||
if(argc < 3) {
|
if(argc < 3) {
|
||||||
fprintf(stderr, "Usage %s run <jobName>\n", argv[0]);
|
fprintf(stderr, "Usage %s run <jobName>\n", argv[0]);
|
||||||
return EXIT_BAD_ARGUMENT;
|
return EXIT_BAD_ARGUMENT;
|
||||||
}
|
}
|
||||||
struct: public kj::TaskSet::ErrorHandler {
|
|
||||||
void taskFailed(kj::Exception&&) override {}
|
|
||||||
} ignoreFailed;
|
|
||||||
kj::TaskSet ts(ignoreFailed);
|
|
||||||
int jobNameIndex = 2;
|
int jobNameIndex = 2;
|
||||||
// make a request for each job specified on the commandline
|
// make a request for each job specified on the commandline
|
||||||
do {
|
do {
|
||||||
@ -157,14 +154,15 @@ int main(int argc, char** argv) {
|
|||||||
req.setJobName(argv[jobNameIndex]);
|
req.setJobName(argv[jobNameIndex]);
|
||||||
int n = setParams(argc - jobNameIndex - 1, &argv[jobNameIndex + 1], req);
|
int n = setParams(argc - jobNameIndex - 1, &argv[jobNameIndex + 1], req);
|
||||||
ts.add(req.send().then([&ret,argv,jobNameIndex](capnp::Response<LaminarCi::RunResults> resp){
|
ts.add(req.send().then([&ret,argv,jobNameIndex](capnp::Response<LaminarCi::RunResults> resp){
|
||||||
|
if(resp.getResult() == LaminarCi::JobResult::UNKNOWN)
|
||||||
|
fprintf(stderr, "Failed to start job '%s'\n", argv[2]);
|
||||||
|
else
|
||||||
printTriggerLink(argv[jobNameIndex], resp.getBuildNum());
|
printTriggerLink(argv[jobNameIndex], resp.getBuildNum());
|
||||||
if(resp.getResult() != LaminarCi::JobResult::SUCCESS) {
|
if(resp.getResult() != LaminarCi::JobResult::SUCCESS)
|
||||||
ret = EXIT_RUN_FAILED;
|
ret = EXIT_RUN_FAILED;
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
jobNameIndex += n + 1;
|
jobNameIndex += n + 1;
|
||||||
} while(jobNameIndex < argc);
|
} while(jobNameIndex < argc);
|
||||||
ts.onEmpty().wait(waitScope);
|
|
||||||
} else if(strcmp(argv[1], "set") == 0) {
|
} else if(strcmp(argv[1], "set") == 0) {
|
||||||
if(argc < 3) {
|
if(argc < 3) {
|
||||||
fprintf(stderr, "Usage %s set param=value\n", argv[0]);
|
fprintf(stderr, "Usage %s set param=value\n", argv[0]);
|
||||||
@ -184,8 +182,10 @@ int main(int argc, char** argv) {
|
|||||||
auto req = laminar.abortRequest();
|
auto req = laminar.abortRequest();
|
||||||
req.getRun().setJob(argv[2]);
|
req.getRun().setJob(argv[2]);
|
||||||
req.getRun().setBuildNum(atoi(argv[3]));
|
req.getRun().setBuildNum(atoi(argv[3]));
|
||||||
if(req.send().wait(waitScope).getResult() != LaminarCi::MethodResult::SUCCESS)
|
ts.add(req.send().then([&ret](capnp::Response<LaminarCi::AbortResults> resp){
|
||||||
|
if(resp.getResult() != LaminarCi::MethodResult::SUCCESS)
|
||||||
ret = EXIT_OPERATION_FAILED;
|
ret = EXIT_OPERATION_FAILED;
|
||||||
|
}));
|
||||||
} else if(strcmp(argv[1], "show-jobs") == 0) {
|
} else if(strcmp(argv[1], "show-jobs") == 0) {
|
||||||
if(argc != 2) {
|
if(argc != 2) {
|
||||||
fprintf(stderr, "Usage: %s show-jobs\n", argv[0]);
|
fprintf(stderr, "Usage: %s show-jobs\n", argv[0]);
|
||||||
@ -215,5 +215,7 @@ int main(int argc, char** argv) {
|
|||||||
return EXIT_BAD_ARGUMENT;
|
return EXIT_BAD_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ts.onEmpty().wait(waitScope);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user