diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-17 16:14:12 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-19 09:50:37 +0200 |
commit | c8394c2ffc3688356cf985d46e8ce56d72050f6a (patch) | |
tree | 2a5deb6ed40f3e8daca90c02711cbc3aba3f548c /src/buildtool/main/retry.cpp | |
parent | 31b782119138859c29ac8ff54bcfe19aa00fca42 (diff) | |
download | justbuild-c8394c2ffc3688356cf985d46e8ce56d72050f6a.tar.gz |
Remove the RetryConfig singleton
...and replace it with instances created early via a builder
pattern.
Diffstat (limited to 'src/buildtool/main/retry.cpp')
-rw-r--r-- | src/buildtool/main/retry.cpp | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/buildtool/main/retry.cpp b/src/buildtool/main/retry.cpp index c7c100cf..96669e05 100644 --- a/src/buildtool/main/retry.cpp +++ b/src/buildtool/main/retry.cpp @@ -14,41 +14,22 @@ #include "src/buildtool/main/retry.hpp" -#ifdef BOOTSTRAP_BUILD_TOOL +#include <utility> // std::move -[[nodiscard]] auto SetupRetryConfig(RetryArguments const& args) -> bool { - return true; -} - -#else - -#include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" -[[nodiscard]] auto SetupRetryConfig(RetryArguments const& args) -> bool { - if (args.max_attempts) { - if (!RetryConfig::SetMaxAttempts(*args.max_attempts)) { - Logger::Log(LogLevel::Error, "Invalid value for max-attempts."); - return false; - } - } - if (args.initial_backoff_seconds) { - if (!RetryConfig::SetInitialBackoffSeconds( - *args.initial_backoff_seconds)) { - Logger::Log(LogLevel::Error, - "Invalid value for initial-backoff-seconds."); - return false; - } - } - if (args.max_backoff_seconds) { - if (!RetryConfig::SetMaxBackoffSeconds(*args.max_backoff_seconds)) { - Logger::Log(LogLevel::Error, - "Invalid value for max-backoff-seconds."); - return false; - } +[[nodiscard]] auto CreateRetryConfig(RetryArguments const& args) + -> std::optional<RetryConfig> { + RetryConfig::Builder builder; + auto config = builder.SetInitialBackoffSeconds(args.initial_backoff_seconds) + .SetMaxBackoffSeconds(args.max_backoff_seconds) + .SetMaxAttempts(args.max_attempts) + .Build(); + + if (config) { + return *std::move(config); } - return true; + Logger::Log(LogLevel::Error, config.error()); + return std::nullopt; } - -#endif // BOOTSTRAP_BUILD_TOOL |