1
0
mirror of https://github.com/ohwgiles/laminar.git synced 2024-10-27 20:34:20 +00:00

additional fixes for #79: chunked http log

use correct sqlite column name
remove redundant code, tidy implementation
This commit is contained in:
Oliver Giles 2019-02-17 22:51:11 +02:00
parent cec4721e52
commit 807901c719
2 changed files with 6 additions and 8 deletions

View File

@ -126,7 +126,7 @@ uint Laminar::latestRun(std::string job) {
auto it = activeJobs.byJobName().equal_range(job); auto it = activeJobs.byJobName().equal_range(job);
if(it.first == it.second) { if(it.first == it.second) {
uint result = 0; uint result = 0;
db->stmt("SELECT MAX(buildNum) FROM builds WHERE name = ?") db->stmt("SELECT MAX(number) FROM builds WHERE name = ?")
.bind(job) .bind(job)
.fetch<uint>([&](uint x){ .fetch<uint>([&](uint x){
result = x; result = x;
@ -145,8 +145,7 @@ bool Laminar::handleLogRequest(std::string name, uint num, std::string& output,
complete = false; complete = false;
return true; return true;
} else { // it must be finished, fetch it from the database } else { // it must be finished, fetch it from the database
const char* stmt = num == 0 ? "SELECT output, outputLen FROM builds WHERE name = ? ORDER BY number DESC LIMIT 1" : "SELECT output, outputLen FROM builds WHERE name = ? AND number = ?" ; db->stmt("SELECT output, outputLen FROM builds WHERE name = ? AND number = ?")
db->stmt(stmt)
.bind(name, num) .bind(name, num)
.fetch<str,int>([&](str maybeZipped, unsigned long sz) { .fetch<str,int>([&](str maybeZipped, unsigned long sz) {
str log(sz,'\0'); str log(sz,'\0');

View File

@ -356,12 +356,13 @@ private:
name = path.slice(0, *sep).begin(); name = path.slice(0, *sep).begin();
kj::StringPtr tail = path.slice(*sep+1); kj::StringPtr tail = path.slice(*sep+1);
num = static_cast<uint>(atoi(tail.begin())); num = static_cast<uint>(atoi(tail.begin()));
if(num > 0 || tail == "latest") {
name.erase(*sep); name.erase(*sep);
if(tail == "latest")
num = laminar.latestRun(name);
if(num > 0)
return true; return true;
} }
} }
}
return false; return false;
} }
@ -407,8 +408,6 @@ private:
} else if(parseLogEndpoint(url, name, num)) { } else if(parseLogEndpoint(url, name, num)) {
kj::Own<HttpChunkedClient> cc = kj::heap<HttpChunkedClient>(laminar); kj::Own<HttpChunkedClient> cc = kj::heap<HttpChunkedClient>(laminar);
cc->scope.job = name; cc->scope.job = name;
if(num == 0)
num = laminar.latestRun(name);
cc->scope.num = num; cc->scope.num = num;
bool complete; bool complete;
std::string output; std::string output;