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

+26 -10
View File
@@ -1453,6 +1453,7 @@ struct WorkerCmdOptions {
std::optional<std::string> registry_arg;
std::optional<std::string> action_key_arg;
std::optional<std::string> record_arg;
bool queue_mode{false};
std::string project_arg;
std::optional<std::string> build_arg;
std::string token_env{"VBS_REGISTRY_TOKEN"};
@@ -1460,8 +1461,9 @@ struct WorkerCmdOptions {
};
int execute_worker_command(const WorkerCmdOptions &opts) {
if (!opts.registry_arg || !opts.action_key_arg || !opts.record_arg) {
std::cerr << "vbs worker: --registry, --action-key, and --record are required\n";
if (!opts.registry_arg || !opts.record_arg || (!opts.action_key_arg && !opts.queue_mode)) {
std::cerr << "vbs worker: --registry, --record, and --action-key (or --queue) are "
"required\n";
return 2;
}
int lease_seconds = 60;
@@ -1472,7 +1474,6 @@ int execute_worker_command(const WorkerCmdOptions &opts) {
return 2;
}
const std::string registry = *opts.registry_arg;
const std::string action_key = *opts.action_key_arg;
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
auto record_text = Void::FileSystem::read_file(*opts.record_arg);
@@ -1506,13 +1507,26 @@ int execute_worker_command(const WorkerCmdOptions &opts) {
}
Void::Log::info("Worker", "Registered as {}", registration->worker_id);
auto leased =
Package::lease_action(registry, action_key, registration->worker_id, lease_seconds, auth);
if (!leased) {
std::cerr << "vbs worker: " << leased.error().message() << '\n';
return 1;
Package::LeasedAction leased;
if (opts.queue_mode && !opts.action_key_arg) {
auto queued =
Package::lease_queued_action(registry, registration->worker_id, lease_seconds, auth);
if (!queued) {
std::cerr << "vbs worker: " << queued.error().message() << '\n';
return 1;
}
leased = std::move(*queued);
} else {
auto direct = Package::lease_action(registry, *opts.action_key_arg, registration->worker_id,
lease_seconds, auth);
if (!direct) {
std::cerr << "vbs worker: " << direct.error().message() << '\n';
return 1;
}
leased = std::move(*direct);
}
Void::Log::info("Worker", "Leased action {} until epoch {}", action_key, leased->expires_epoch);
const std::string action_key = leased.action_key;
Void::Log::info("Worker", "Leased action {} until epoch {}", action_key, leased.expires_epoch);
State::RemoteCacheConfig remote;
remote.url = registry;
@@ -1550,7 +1564,7 @@ int execute_worker_command(const WorkerCmdOptions &opts) {
<< '\n';
return 1;
}
if (auto submitted = Package::submit_action_result(registry, action_key, leased->lease_token,
if (auto submitted = Package::submit_action_result(registry, action_key, leased.lease_token,
*record_text, auth);
!submitted) {
std::cerr << "vbs worker: " << submitted.error().message() << '\n';
@@ -3283,6 +3297,8 @@ int main(int argc, char **argv) {
worker_opts.registry_arg)
.option("--action-key", "", "Action key to lease and publish", worker_opts.action_key_arg)
.option("--record", "", "Action record JSON file to publish", worker_opts.record_arg)
.flag("--queue", "", "Lease the next action from the registry queue",
worker_opts.queue_mode)
.option_default("--project", "-C", "Project directory", worker_opts.project_arg, cwd)
.option("--build-dir", "-B", "Build directory", worker_opts.build_arg)
.option_default("--token-env", "", "Environment variable holding bearer token",