Moving to a poll method for workers, and daggyd-preserved capacities

This commit is contained in:
Ian Roddis
2021-12-24 10:21:19 -04:00
parent 0914ede8fb
commit 779d6adaea
7 changed files with 199 additions and 128 deletions

View File

@@ -234,7 +234,7 @@ namespace daggy {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriter);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 2);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
if (trace) {
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, http_trace);
@@ -254,8 +254,9 @@ namespace daggy {
if (res != CURLE_OK) {
curl_easy_cleanup(curl);
throw std::runtime_error(std::string{"CURL Failed: "} +
curl_easy_strerror(res));
response.code = HTTPCode::Server_Error;
response.body = std::string{"CURL Failed: "} + curl_easy_strerror(res);
return response;
}
curl_easy_cleanup(curl);
@@ -275,7 +276,18 @@ namespace daggy {
auto response = HTTP_REQUEST(url, payload, method);
rj::Document doc;
checkRJParse(doc.Parse(response.body.c_str()));
if (response.code == HTTPCode::Server_Error) {
doc.SetObject();
auto &alloc = doc.GetAllocator();
doc.AddMember("error",
rj::Value().SetString(response.body.c_str(),
response.body.size(), alloc),
alloc);
}
else {
checkRJParse(doc.Parse(response.body.c_str()));
}
return std::make_pair(response.code, std::move(doc));
}