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 memoryMB;
|
||||
void operator==(const Capacity &other)
|
||||
{
|
||||
cores = other.cores;
|
||||
memoryMB = other.memoryMB;
|
||||
}
|
||||
};
|
||||
|
||||
std::string capacityToJSON(const Capacity &cap);
|
||||
|
||||
@@ -139,11 +139,23 @@ std::future<AttemptRecord> DaggyRunnerTaskExecutor::execute(
|
||||
|
||||
{
|
||||
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");
|
||||
if (result.code != 200)
|
||||
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 memoryMB = (caps.current.memoryMB - taskUsed.memoryMB);
|
||||
|
||||
@@ -203,10 +215,14 @@ void DaggyRunnerTaskExecutor::addRunner(const std::string &url)
|
||||
// Try and get the capacity
|
||||
const auto &[code, doc] = JSON_HTTP_REQUEST(url + "/v1/capacity");
|
||||
if (code != HTTPCode::Ok) {
|
||||
std::cerr << "Failed to add runner " << url << ": "
|
||||
<< doc["error"].GetString() << std::endl;
|
||||
std::cerr << "Failed to contact runner " << url << ": "
|
||||
<< doc["error"].GetString()
|
||||
<< ", will attempt to set capacities later" << std::endl;
|
||||
|
||||
runners_.emplace(url, RunnerCapacity{});
|
||||
return;
|
||||
}
|
||||
|
||||
RunnerCapacity caps{.current = capacityFromJSON(doc["current"]),
|
||||
.total = capacityFromJSON(doc["total"])};
|
||||
std::lock_guard<std::mutex> lock(runnersGuard_);
|
||||
|
||||
Reference in New Issue
Block a user