feat(worker): lease queued actions in vbs worker
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 3s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 32s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 52s

This commit is contained in:
faumaray committed 2026-12-05 11:36:17 +03:00
1 parent 2776e459e3
commit 452b2e315d
7 files changed
+107 -10

No files matched your search

+40
View File
@@ -910,6 +910,46 @@ lease_action(std::string_view registry_url, std::string_view action_key, std::st
return leased;
}
Void::Result::Result<LeasedAction, Void::Result::Error>
lease_queued_action(std::string_view registry_url, std::string_view worker_id,
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 body = std::format("{{\"worker_id\":{},\"lease_seconds\":{}}}",
json_quote_of(worker_id), lease_seconds);
auto reply =
send_http_request(*parsed_url, "POST", "/api/v1/queue/lease", bearer_headers(auth), body);
if (!reply) {
return std::unexpected{reply.error()};
}
if (reply->status != 200) {
return std::unexpected{make_error(
reply->status == 404 ? Void::System::SystemErrorCode::not_found
: reply->status == 401 || reply->status == 403
? Void::System::SystemErrorCode::permission_denied
: Void::System::SystemErrorCode::io_error,
std::format("queue lease 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 queue lease response")};
}
LeasedAction leased;
leased.action_key = get_str(*object, "action_key");
leased.worker_id = get_str(*object, "worker_id");
leased.lease_token = get_str(*object, "lease_token");
leased.expires_epoch = get_i64(*object, "expires_epoch", 0);
if (leased.action_key.empty() || leased.lease_token.empty()) {
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
"queue lease response is incomplete")};
}
return leased;
}
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,