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
@@ -950,6 +950,39 @@ lease_queued_action(std::string_view registry_url, std::string_view worker_id,
return leased;
}
Void::Result::Result<std::int64_t, Void::Result::Error>
renew_action_lease(std::string_view registry_url, std::string_view action_key,
std::string_view lease_token, std::int64_t lease_seconds,
const RegistryAuth &auth) {
auto parsed_url = parse_registry_url(registry_url);
if (!parsed_url) {
return std::unexpected{parsed_url.error()};
}
const std::string path =
"/api/v1/actions/" + Void::Encoding::Url::encode(action_key) + "/renew";
const std::string body = std::format("{{\"lease_token\":{},\"lease_seconds\":{}}}",
json_quote_of(lease_token), lease_seconds);
auto reply = send_http_request(*parsed_url, "POST", path, bearer_headers(auth), body);
if (!reply) {
return std::unexpected{reply.error()};
}
if (reply->status != 200) {
return std::unexpected{make_error(
reply->status == 409 ? Void::System::SystemErrorCode::busy
: reply->status == 403 ? Void::System::SystemErrorCode::permission_denied
: reply->status == 400 ? Void::System::SystemErrorCode::invalid_argument
: Void::System::SystemErrorCode::io_error,
std::format("lease renewal failed with HTTP {}: {}", reply->status, reply->body))};
}
auto json = Void::Json::Strict::parse(reply->body);
const auto *object = json ? std::get_if<JsonVal::Object>(&json->value) : nullptr;
if (!object) {
return std::unexpected{
make_error(Void::System::SystemErrorCode::io_error, "invalid lease renewal response")};
}
return get_i64(*object, "expires_epoch", 0);
}
Void::Result::Result<void, Void::Result::Error> submit_action_result(std::string_view registry_url,
std::string_view action_key,
std::string_view lease_token,