diff options
| author | spacelord <[email protected]> | 2022-02-10 16:48:15 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:48:15 +0300 | 
| commit | 16747e4f77455cca4932df21eb76f12cb0a97a5c (patch) | |
| tree | 4dd6da4102d99d0d69dec53c1050d290a850a9f2 /library/cpp/retry | |
| parent | a817f5de12611ec73085eba17f8ec7740a46bdb7 (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/retry')
| -rw-r--r-- | library/cpp/retry/retry.cpp | 12 | ||||
| -rw-r--r-- | library/cpp/retry/retry.h | 46 | 
2 files changed, 29 insertions, 29 deletions
| diff --git a/library/cpp/retry/retry.cpp b/library/cpp/retry/retry.cpp index 92466cdeca5..efb2ec3dbc0 100644 --- a/library/cpp/retry/retry.cpp +++ b/library/cpp/retry/retry.cpp @@ -1,10 +1,10 @@ -#include "retry.h" - -#include <util/stream/output.h> - +#include "retry.h"  +  +#include <util/stream/output.h>  +   void DoWithRetry(std::function<void()> func, TRetryOptions retryOptions) { -    DoWithRetry(func, retryOptions, true); -} +    DoWithRetry(func, retryOptions, true);  +}   bool DoWithRetryOnRetCode(std::function<bool()> func, TRetryOptions retryOptions) {      for (ui32 attempt = 0; attempt <= retryOptions.RetryCount; ++attempt) { diff --git a/library/cpp/retry/retry.h b/library/cpp/retry/retry.h index c47ff5070fe..dc70f953b0b 100644 --- a/library/cpp/retry/retry.h +++ b/library/cpp/retry/retry.h @@ -1,15 +1,15 @@ -#pragma once - +#pragma once  +   #include "utils.h"  #include <library/cpp/retry/protos/retry_options.pb.h> -#include <util/datetime/base.h> -#include <util/generic/maybe.h> -#include <util/generic/typetraits.h> -#include <util/generic/yexception.h> +#include <util/datetime/base.h>  +#include <util/generic/maybe.h>  +#include <util/generic/typetraits.h>  +#include <util/generic/yexception.h>   #include <functional> - +   struct TRetryOptions {      ui32 RetryCount; @@ -18,7 +18,7 @@ struct TRetryOptions {      TDuration SleepRandomDelta;      TDuration SleepIncrement;      TDuration SleepExponentialMultiplier; - +       std::function<void(TDuration)> SleepFunction;      TRetryOptions(ui32 retryCount = 3, TDuration sleepDuration = TDuration::Seconds(1), TDuration sleepRandomDelta = TDuration::Zero(), @@ -32,17 +32,17 @@ struct TRetryOptions {          , SleepFunction(sleepFunction)      {      } - +       TRetryOptions& WithCount(ui32 retryCount) {          RetryCount = retryCount;          return *this;      } - +       TRetryOptions& WithSleep(TDuration sleepDuration) {          SleepDuration = sleepDuration;          return *this;      } - +       TRetryOptions& WithRandomDelta(TDuration sleepRandomDelta) {          SleepRandomDelta = sleepRandomDelta;          return *this; @@ -71,16 +71,16 @@ struct TRetryOptions {      static TRetryOptions Count(ui32 retryCount) {          return TRetryOptions(retryCount);      } - +       static TRetryOptions Default() {          return TRetryOptions(); -    } - +    }  +       static TRetryOptions NoRetry() {          return TRetryOptions(0); -    } +    }   }; - +   template <typename TResult, typename TException = yexception>  TMaybe<TResult> DoWithRetry(std::function<TResult()> func, std::function<void(const TException&)> onFail, TRetryOptions retryOptions, bool throwLast) {      for (ui32 attempt = 0; attempt <= retryOptions.RetryCount; ++attempt) { @@ -91,16 +91,16 @@ TMaybe<TResult> DoWithRetry(std::function<TResult()> func, std::function<void(co              if (attempt == retryOptions.RetryCount) {                  if (throwLast) {                      throw; -                } +                }               } else {                  auto sleep = retryOptions.SleepFunction;                  sleep(retryOptions.GetTimeToSleep(attempt)); -            } -        } -    } +            }  +        }  +    }       return Nothing();  } - +   template <typename TResult, typename TException = yexception>  TMaybe<TResult> DoWithRetry(std::function<TResult()> func, TRetryOptions retryOptions, bool throwLast) {      return DoWithRetry<TResult, TException>(func, [](const TException&){}, retryOptions, throwLast); @@ -123,9 +123,9 @@ bool DoWithRetry(std::function<void()> func, TRetryOptions retryOptions, bool th      };      return DoWithRetry<void*, TException>(f, [](const TException&){}, retryOptions, throwLast).Defined();  } - +   void DoWithRetry(std::function<void()> func, TRetryOptions retryOptions); - +   bool DoWithRetryOnRetCode(std::function<bool()> func, TRetryOptions retryOptions);  Y_DECLARE_PODTYPE(TRetryOptions); | 
