feat(worker): renew leases and watch an idle queue
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 5s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 2s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 13s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 49s

This commit is contained in:
faumaray committed 2026-12-05 12:03:46 +03:00
1 parent 8dac19c3ea
commit 55bc0529b9
8 files changed
+152 -17

No files matched your search

+33
View File
@@ -1191,6 +1191,39 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
",\"record\":" + *record_text + "}\n");
}
if (segs.size() == 5 && segs[4] == "renew" && req.method == "POST") {
const std::string &action_key = segs[3];
prune_expired_leases();
const auto lease_it = action_leases_.find(action_key);
if (lease_it == action_leases_.end()) {
return HttpResponse::error_json(409, "not_leased", "action has no active lease");
}
auto parsed = Void::Json::Strict::parse(req.body);
const auto *obj = parsed ? std::get_if<JsonVal::Object>(&parsed->value) : nullptr;
if (obj == nullptr) {
return HttpResponse::error_json(400, "invalid_json", "renew body must be JSON");
}
if (get_str(*obj, "lease_token") != lease_it->second.lease_token) {
return HttpResponse::error_json(403, "invalid_lease_token",
"lease token does not match");
}
std::int64_t lease_seconds = 60;
if (const auto it = obj->find("lease_seconds"); it != obj->end()) {
const auto *value = std::get_if<std::int64_t>(&it->second.value);
if (!value || *value <= 0 || *value > 3600) {
return HttpResponse::error_json(400, "invalid_lease",
"lease_seconds must be 1..3600");
}
lease_seconds = *value;
}
lease_it->second.expires_epoch = now_epoch() + lease_seconds;
append_audit_locked(principal->username, "action.renew", action_key, "ok", "");
return HttpResponse::json(
200, std::format("{{\"action_key\":{},\"lease_token\":{},\"expires_epoch\":{}}}\n",
json_quote(action_key), json_quote(lease_it->second.lease_token),
lease_it->second.expires_epoch));
}
if (segs.size() == 5 && segs[4] == "result" && req.method == "POST") {
const std::string &action_key = segs[3];
if (!is_sha256_hex(action_key)) {