summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/man/just-serve-config.5.md12
-rw-r--r--src/buildtool/main/TARGETS1
-rw-r--r--src/buildtool/main/serve.cpp57
3 files changed, 70 insertions, 0 deletions
diff --git a/share/man/just-serve-config.5.md b/share/man/just-serve-config.5.md
index f01536eb..3273bdc6 100644
--- a/share/man/just-serve-config.5.md
+++ b/share/man/just-serve-config.5.md
@@ -70,6 +70,18 @@ The configuration file is given by a JSON object.
execution address in a NAME:PORT format.
For subkey *`"compatible"`* the value is a flag which specifies whether
the remote endpoint uses the original remote execution protocol.
+ If the key *`"execution endpoint"`* is given, the following three keys will
+ be evaluated as well:
+ - *`"max-attempts"`*: the value must be a number specifying the maximum
+ number of attempts to perform when a remote procedure call (to the
+ *`"execution endpoint"`* given) fails because the resource is unavailable.
+ - *`"initial-backoff-seconds"`*: the value must be a number; before retrying
+ the second time, the client will wait the given amount of seconds plus a jitter,
+ to better distribute the workload.
+ - *`"max-backoff-seconds"`*: the value must be a number; from the third
+ attempt (included) on, the backoff time is doubled at each attempt, until
+ it exceeds the `"max-backoff-seconds"` value. From that point, the waiting
+ time is computed as `"max-backoff-seconds"` value plus a jitter.
- The value for the key *`"jobs"`* specifies the number of jobs to run. If
unset, the number of available cores is used.
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"];