Adding discovery of capacities after the fact.
This commit is contained in:
@@ -15,6 +15,11 @@ namespace daggy::executors::task {
|
|||||||
{
|
{
|
||||||
ssize_t cores;
|
ssize_t cores;
|
||||||
ssize_t memoryMB;
|
ssize_t memoryMB;
|
||||||
|
void operator==(const Capacity &other)
|
||||||
|
{
|
||||||
|
cores = other.cores;
|
||||||
|
memoryMB = other.memoryMB;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string capacityToJSON(const Capacity &cap);
|
std::string capacityToJSON(const Capacity &cap);
|
||||||
|
|||||||
@@ -139,11 +139,23 @@ std::future<AttemptRecord> DaggyRunnerTaskExecutor::execute(
|
|||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(runnersGuard_);
|
std::lock_guard<std::mutex> lock(runnersGuard_);
|
||||||
for (const auto &[runner, caps] : runners_) {
|
for (auto &[runner, caps] : runners_) {
|
||||||
const auto result = HTTP_REQUEST(runner + "/ready");
|
const auto result = HTTP_REQUEST(runner + "/ready");
|
||||||
if (result.code != 200)
|
if (result.code != 200)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Set capacities if they haven't been discovered yet
|
||||||
|
if (caps.total.cores == 0) {
|
||||||
|
const auto &[code, json] = JSON_HTTP_REQUEST(runner + "/v1/capacity");
|
||||||
|
if (code != HTTPCode::Ok) {
|
||||||
|
std::cerr << "Runner " << runner
|
||||||
|
<< " appears to be up, but cannot retrieve capacity";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
caps.current = capacityFromJSON(json["current"]);
|
||||||
|
caps.total = capacityFromJSON(json["total"]);
|
||||||
|
}
|
||||||
|
|
||||||
double cores = (caps.current.cores - taskUsed.cores);
|
double cores = (caps.current.cores - taskUsed.cores);
|
||||||
double memoryMB = (caps.current.memoryMB - taskUsed.memoryMB);
|
double memoryMB = (caps.current.memoryMB - taskUsed.memoryMB);
|
||||||
|
|
||||||
@@ -203,10 +215,14 @@ void DaggyRunnerTaskExecutor::addRunner(const std::string &url)
|
|||||||
// Try and get the capacity
|
// Try and get the capacity
|
||||||
const auto &[code, doc] = JSON_HTTP_REQUEST(url + "/v1/capacity");
|
const auto &[code, doc] = JSON_HTTP_REQUEST(url + "/v1/capacity");
|
||||||
if (code != HTTPCode::Ok) {
|
if (code != HTTPCode::Ok) {
|
||||||
std::cerr << "Failed to add runner " << url << ": "
|
std::cerr << "Failed to contact runner " << url << ": "
|
||||||
<< doc["error"].GetString() << std::endl;
|
<< doc["error"].GetString()
|
||||||
|
<< ", will attempt to set capacities later" << std::endl;
|
||||||
|
|
||||||
|
runners_.emplace(url, RunnerCapacity{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RunnerCapacity caps{.current = capacityFromJSON(doc["current"]),
|
RunnerCapacity caps{.current = capacityFromJSON(doc["current"]),
|
||||||
.total = capacityFromJSON(doc["total"])};
|
.total = capacityFromJSON(doc["total"])};
|
||||||
std::lock_guard<std::mutex> lock(runnersGuard_);
|
std::lock_guard<std::mutex> lock(runnersGuard_);
|
||||||
|
|||||||
Reference in New Issue
Block a user