From c8394c2ffc3688356cf985d46e8ce56d72050f6a Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Wed, 17 Jul 2024 16:14:12 +0200 Subject: Remove the RetryConfig singleton ...and replace it with instances created early via a builder pattern. --- src/buildtool/main/retry.cpp | 45 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) (limited to 'src/buildtool/main/retry.cpp') 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 // 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::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 -- cgit v1.2.3