diff options
author | Alberto Sartori <alberto.sartori@huawei.com> | 2023-12-13 14:44:21 +0100 |
---|---|---|
committer | Alberto Sartori <alberto.sartori@huawei.com> | 2023-12-13 23:04:36 +0100 |
commit | 3fb25cdc64ca77c75e0835f3bbd8965980d6ac70 (patch) | |
tree | 0f2a4563f06d8835b37f1f7503c0a29a1137bbd4 /src | |
parent | 48890ad9951a31cbeae55413c205a2b6b1c24a81 (diff) | |
download | justbuild-3fb25cdc64ca77c75e0835f3bbd8965980d6ac70.tar.gz |
just serve: allowing for tuning retry strategy in the configuration file
While parsing the configuration file, if the key `"execution
endpoint"` is present, the following three keys are evaluated as well:
- "max-attempts"
- "initial-backoff-seconds"
- "max-backoff-seconds"
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/main/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/main/serve.cpp | 57 |
2 files changed, 58 insertions, 0 deletions
diff --git a/src/buildtool/main/TARGETS b/src/buildtool/main/TARGETS index 21ed04aa..d955e766 100644 --- a/src/buildtool/main/TARGETS +++ b/src/buildtool/main/TARGETS @@ -202,6 +202,7 @@ , ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] , "common" + , ["src/buildtool/common/remote", "retry_parameters"] ] } , "build_utils": diff --git a/src/buildtool/main/serve.cpp b/src/buildtool/main/serve.cpp index 32da7801..1a2add16 100644 --- a/src/buildtool/main/serve.cpp +++ b/src/buildtool/main/serve.cpp @@ -23,11 +23,65 @@ #include "nlohmann/json.hpp" #include "src/buildtool/build_engine/expression/configuration.hpp" #include "src/buildtool/build_engine/expression/expression.hpp" +#include "src/buildtool/common/remote/retry_parameters.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" #include "src/buildtool/main/exit_codes.hpp" +[[nodiscard]] auto ParseRetryCliOptions(Configuration const& config) noexcept + -> bool { + auto max_attempts = config["max-attempts"]; + if (max_attempts.IsNotNull()) { + if (!max_attempts->IsNumber()) { + Logger::Log( + LogLevel::Error, + "Invalid value for \"max-attempts\" {}. It must be a number.", + max_attempts->ToString()); + return false; + } + if (!Retry::SetMaxAttempts(max_attempts->Number())) { + Logger::Log(LogLevel::Error, + "Invalid value for \"max-attempts\" {}.", + max_attempts->Number()); + return false; + } + } + auto initial_backoff = config["initial-backoff-seconds"]; + if (initial_backoff.IsNotNull()) { + if (!initial_backoff->IsNumber()) { + Logger::Log(LogLevel::Error, + "Invalid value \"initial-backoff-seconds\" {}. It must " + "be a number.", + initial_backoff->ToString()); + return false; + } + if (!Retry::SetMaxAttempts(initial_backoff->Number())) { + Logger::Log(LogLevel::Error, + "Invalid value for \"initial-backoff-seconds\" {}.", + initial_backoff->Number()); + return false; + } + } + auto max_backoff = config["max-backoff-seconds"]; + if (max_backoff.IsNotNull()) { + if (!max_backoff->IsNumber()) { + Logger::Log(LogLevel::Error, + "Invalid value for \"max-backoff-seconds\" {}. It must " + "be a number.", + max_backoff->ToString()); + return false; + } + if (!Retry::SetMaxAttempts(max_backoff->Number())) { + Logger::Log(LogLevel::Error, + "Invalid value for \"max-backoff-seconds\" {}.", + max_backoff->Number()); + return false; + } + } + return true; +} + void ReadJustServeConfig(gsl::not_null<CommandLineArguments*> const& clargs) { Configuration serve_config{}; if (FileSystemManager::IsFile(clargs->serve.config)) { @@ -347,6 +401,9 @@ void ReadJustServeConfig(gsl::not_null<CommandLineArguments*> const& clargs) { } clargs->endpoint.remote_execution_address = address->String(); } + if (!ParseRetryCliOptions(serve_config)) { + std::exit(kExitFailure); + } } // read jobs value auto jobs = serve_config["jobs"]; |