Seems to work now
This commit is contained in:
@@ -77,14 +77,15 @@ namespace daggy::daggyr {
|
||||
bool resolved;
|
||||
};
|
||||
|
||||
std::mutex resolvedGuard_;
|
||||
std::string resolved_;
|
||||
size_t nResolved_;
|
||||
|
||||
void monitor();
|
||||
std::atomic<bool> running_;
|
||||
std::thread monitorWorker_;
|
||||
|
||||
std::mutex pendingGuard_;
|
||||
std::unordered_map<TaskID, PendingJob> pending_;
|
||||
|
||||
std::mutex resolvedGuard_;
|
||||
std::deque<std::string> resolved_;
|
||||
};
|
||||
} // namespace daggy::daggyr
|
||||
|
||||
@@ -38,6 +38,8 @@ namespace daggy::daggyr {
|
||||
, executor_(maxCores)
|
||||
, maxCapacity_{maxCores, maxMemoryMB}
|
||||
, curCapacity_{maxCores, maxMemoryMB}
|
||||
, resolved_("[")
|
||||
, nResolved_(0)
|
||||
, running_(true)
|
||||
, monitorWorker_(&Server::monitor, this)
|
||||
{
|
||||
@@ -200,8 +202,16 @@ namespace daggy::daggyr {
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(resolvedGuard_);
|
||||
for (const auto &[_, item] : payloads)
|
||||
resolved_.push_back(item);
|
||||
for (const auto &[_, item] : payloads) {
|
||||
if (resolved_.empty()) {
|
||||
resolved_ = "[";
|
||||
}
|
||||
|
||||
if (nResolved_ > 0)
|
||||
resolved_ += ',';
|
||||
resolved_ += item;
|
||||
++nResolved_;
|
||||
}
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
@@ -213,37 +223,16 @@ namespace daggy::daggyr {
|
||||
{
|
||||
if (!handleAuth(request))
|
||||
return;
|
||||
auto ss = Clock::now();
|
||||
|
||||
std::stringstream payload;
|
||||
payload << "[";
|
||||
bool first = true;
|
||||
size_t cnt = 0;
|
||||
std::string payload = "[";
|
||||
payload.reserve(65536);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(resolvedGuard_);
|
||||
cnt = resolved_.size();
|
||||
for (const auto &item : resolved_) {
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
payload << ", ";
|
||||
}
|
||||
payload << item;
|
||||
}
|
||||
resolved_.clear();
|
||||
payload.swap(resolved_);
|
||||
nResolved_ = 0;
|
||||
}
|
||||
payload << "]";
|
||||
payload += "]";
|
||||
|
||||
auto payloadStr = payload.str();
|
||||
response.send(Pistache::Http::Code::Ok, payloadStr);
|
||||
auto ee = Clock::now();
|
||||
|
||||
std::cout
|
||||
<< "Completed request: with " << cnt << " updates in"
|
||||
<< " total ("
|
||||
<< std::chrono::duration_cast<std::chrono::nanoseconds>(ee - ss).count()
|
||||
<< " ns)\n";
|
||||
response.send(Pistache::Http::Code::Ok, payload);
|
||||
}
|
||||
|
||||
void Server::handleStopTask(const Pistache::Rest::Request &request,
|
||||
|
||||
@@ -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, 30);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);
|
||||
|
||||
if (trace) {
|
||||
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, http_trace);
|
||||
|
||||
@@ -266,6 +266,7 @@ void DaggyRunnerTaskExecutor::monitor()
|
||||
std::unordered_map<std::string, RunnerCapacity> runners;
|
||||
|
||||
while (running_) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
std::unordered_map<std::pair<DAGRunID, std::string>,
|
||||
std::optional<AttemptRecord>>
|
||||
resolvedJobs;
|
||||
@@ -302,7 +303,11 @@ void DaggyRunnerTaskExecutor::monitor()
|
||||
std::cout << "Unable to poll: " << e.what() << std::endl;
|
||||
continue;
|
||||
}
|
||||
std::cout << "Doc is now: " << doc.Size() << std::endl;
|
||||
|
||||
if (!doc.IsArray()) {
|
||||
std::cout << "Got nonsense from poll: " << dumpJSON(doc) << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto tasks = doc.GetArray();
|
||||
for (size_t idx = 0; idx < tasks.Size(); ++idx) {
|
||||
@@ -338,7 +343,5 @@ void DaggyRunnerTaskExecutor::monitor()
|
||||
runningTasks_.extract(tid);
|
||||
}
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user